Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

var myArray =[], name;?

Tags:

javascript

What purpose does name have in the following statement?

var myArray =[], name;

I usually initialize my arrays as the following:

var myArray =[];
like image 795
burnt1ce Avatar asked Jun 03 '11 21:06

burnt1ce


2 Answers

It is shorthand to

var myArray =[];
var name;

It is matter of personal preference.

like image 90
amit_g Avatar answered Oct 29 '22 20:10

amit_g


You are actually initialising two variables there, myArray and name.

You set myArray to [] and name to undefined, because you don't give any value.

Your code is equivalent to this:

var myArray = [];
var name;
like image 36
lonesomeday Avatar answered Oct 29 '22 20:10

lonesomeday