Skip navigation

Monthly Archives: September 2010


Before reading this blog entry, please have a quick look at my earlier blog entry null typeof shock.

In the earlier blog (null typeof shock), using typeof operator returns misleading value object.

To make it clear,

var myArr = Array();  // creating variable myArr and assigning a array into it
//var myArr = [];  // another way of doing it
alert(typeof(myArr));  // object, NOT array


So how do you make sure if a variable is given, it is an array?

Here comes instanceof operator to rescue.

alert(myArr instanceof Array) // true.

Well, don’t you feel strange to hear typeof and instanceof are operators!! Search and read about it then. In JavaScript you have lot of strange operators like this.

Advertisements