In the Chrome Developer Tools window, I typed in:
> name = ["a", "b", "c"]
["a", "b", "c"]
However, name
became a string:
> typeof name
"string"
> name
"a,b,c"
> name[1]
","
This obviously isn't true for other variable names!
> foo = ["a", "b", "c"]
["a", "b", "c"]
> typeof foo
"object"
> foo[1]
"b"
And name
is defined as the empty string on page load (and, as far as I can tell, cannot become anything other than a string).
So, what's up with name
?
Variable names in JavaScript are often known as identifiers. Identifiers are a sequence of characters in a program that identifies a variable, function, or property. These are the names we use in JavaScript as a name to declare any variable.
We can use variables to store goodies, visitors, and other data. To create a variable in JavaScript, use the let keyword. The statement below creates (in other words: declares) a variable with the name “message”: Now, we can put some data into it by using the assignment operator =:
These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume). The general rules for constructing names for variables (unique identifiers) are: Names can contain letters, digits, underscores, and dollar signs. JavaScript identifiers are case-sensitive.
For example, break or boolean variable names are not valid. JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one. JavaScript variable names are case-sensitive.
When you type name
you are implicitly referencing window.name
, which according to MDN:
Gets/sets the name of the window.
https://developer.mozilla.org/en-US/docs/Web/API/window.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With