What is the correct way on instantiate empty array in javascript?
var array=new Array();
var array=new Array;
var array=[];
All of them look same. Is there any difference?
What is the correct way on instantiate empty array in javascript?
var array=new Array();
var array=new Array;
var array=[];
All of them look same. Is there any difference?
There is one more way:
var array = Array() ;
They all will produce the same result, an empty object Array. I think the best way is using the array literal shortcut [] as it is what use less characters, it is what most people do.
Note that the same does not apply in the case of Boolean, Number and String, as those constructors will return primitives of type 'object' (object Boolean, object Number and object String respectively) while their literals will return primitives of types 'boolean', 'number' and 'string' respectively (and will behave differently in some situations), but array primitive type it is 'object' in any case.