Skip navigation

var k = Array();
alert(typeof(k));

Expecting array…. but k is an object!!!

var k = new Array();
alert(k.length);
Confused…. now it is also an object and length is 0(zero).  cool…

var k = {};
k.name = ‘kanakarajv’;
alert(k.length);
alert(k[‘name’]);
what is length of k? hahaha…. it is undefined.
OK. what is k[‘name’]. hehehe… that is great kanakarajv itself. ;-D

var k = {};
k[‘hid  a#2@&^%’]=’kanakarajv’;  // yes. you are right. there is two spaces in between & special characters also.
alert(k[‘hid  a#2@&^%’]);
sorry guys… javascript alerts kanakarajv

var x = Array();
var y = new Array();
var z = {};

What is the difference between these three and why?

After getting all these shock, I decided to break this mystry.

There is an excellent article about Arrays found at javascript-associative-arrays-considered-harmful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: