Skip navigation

Tag Archives: property


JavaScript have some odd behaviour on object property names. If you know this for first time, you will be shocked. Programmers from other language background will be surprised to know this kind of JavaScript behaviour.

// declare a variable and create a new object with property name and value raja

var myO = {name:"raja"};
alert(myO.name);  //raja

Your shocks starts here…

myO.if = "use reserved word";
alert(myO.if);  //use of reserved word

myO["if else if && || *^ "] = "you can use anything";
alert(myO["if else if && || *^ "]);  //you can use anything

myO[""] = "Surprise";  // no error. even empty is allowed
alert(myO[""]);  // Surprise

Similar article written by mathias