I have two examples . In the first example :
a.
1. var object = {1 : "value"};
alert(object[1]);
2. var object = {1 : "value"};
alert(object["1"]);
In both of the examples , the output is "value". I read in the books that object[1] will find a variable 1 and substitute the value with that.
Since 1 cannot be declared as variable name in javascript (var 1="some var" //not allowed) , is it just alert(object[1]) tries to find the string declared in
var object = {1 : "value"}; and alerts "value".
Because , there is no difference between 1. and 2. example alerts yield the same result.
b.
1.
var object = {a : "value"};
alert(object["a"]);
The above example is pretty much clear that it is finding out string "a".
2.
var object = {a : "value"};
alert(object[a]);
The above example is an error , since we havent declared
var a = "some";
I am just curious to know the difference between a. 1 and a.2 and also if my understanding is correct wrt these examples?
a