Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7691493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:38:14+00:00 2026-05-31T20:38:14+00:00

Following is some codes and output from the Chrome Developers’ Console Case 1: var

  • 0

Following is some codes and output from the Chrome Developers’ Console

Case 1:

var myarr = document.location.hostname.split(".");    //typed
undefined                                             //output
myarr[0]                                              //typed
"ptamz"                                               //output: ONE

Case 2:

var name = document.location.hostname.split(".");     //typed
undefined                                             //output
name[0]                                               //typed
"p"                                                   //output: TWO

Why are the two outputs (commented Output: ONE, and Output: TWO) different?

Screenshot:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:38:15+00:00Added an answer on May 31, 2026 at 8:38 pm

    name is a property of window. It appears that when you try to set that property to an array, the keys are joined with a comma (the result of calling toString on an array). So you are actually setting the window.name property to the concatenation of each element of document.location.hostname.split("."), separated by commas.

    Here’s a screenshot from my Chrome console demonstrating what happens:

    enter image description here

    The reason name[0] then results in p is that you can access the characters of strings using square brackets:

    name = "hello,world";
    console.log(name[0]); //"h"
    

    Edit

    As others have mentioned, this will only be the case in the global scope. You are free to declare a variable named name inside a descendant scope. Although, obviously, omitting the var keyword in this case would still result in you accessing window.name:

    function example() {
        var name = ["hello", "world"];
        console.log(name); //["hello", "world"]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble understanding the output from the following code: int main(void) {
I have the following subroutine OutputingReorderedVectors, which aims to output vectors following some pre-specified
I have the following code in a test case on jsPerf: var arr =
I have some output from 3rd party software: Sample XML from the software: <testsuite
I am using JAXP to generate and parse an XML document from which some
I'm building a Python ISO generation app, and I'm getting some wierd output from
Is there some kind of a tool or some better output from javac to
I am pulling some data from a mysql table via the following: $result =
The following is an excerpt from some code that I'm experimenting with: has buffer
The following HTML is output from a CMS. (Yes, it is from the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.