Skip navigation

We can store different types of values in a single JavaScript array. To know how consider the following code (refer comments).

// declare a variable & store boolean value in it
var bVal = true;
// declare another variable myArr and store an array in it
// Store different values like Number, String, Data, Function(!!), boolean
var myArr = Array(2,"raja",Date(),function(){return 2;},bVal);
alert(myArr[4]);  // true
alert(myArr[3]());  // 2

The function stored at index value 3 is an anonymous function. This concept will be new to “non” JavaScript programmers and “new” JavaScript programmers.

There are lot other this kind of concepts makes JavaScript more powerful, compact, flexible. So I invite you all to explore JavaScript more and more…

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: