0

What does below declaration mean ?

var line = {}, lines = [], hasmore;

I understand that lines = [] is an array , but I have no idea about the others.

Actual code is to reading file line by line using javascript xpcom

var line = {}, lines = [], hasmore;
do {
      hasmore = istream.readLine(line);
      lines.push(line.value); 
} while(hasmore);
mantal
  • 1,093
  • 1
  • 20
  • 38
  • 1
    Remember that JavaScript does not keep track of variable types at "compile-time." `x=[]; x=3; x="hi";` is perfectly valid (though not recommended.) The type of a variable is determined by how you use it, not how you declare it. – Flight Odyssey Nov 27 '13 at 04:49
  • possible duplicate of [What does variable declaration with multiple comma separated values mean (e.g. var a = b,c,d;)](http://stackoverflow.com/questions/11076750/what-does-variable-declaration-with-multiple-comma-separated-values-mean-e-g-v) – Felix Kling Nov 27 '13 at 05:00
  • and [var myArray =\[\], name;?](http://stackoverflow.com/q/6232778/218196) – Felix Kling Nov 27 '13 at 05:00
  • and [What does a comma do in assignment statements in JavaScript?](http://stackoverflow.com/q/9568905/218196) – Felix Kling Nov 27 '13 at 05:01

3 Answers3

4

It's creating 3 variables

var line = {};   // creates an object
var lines = [];  // creates an array
var hasmore;     // undefined
jasonscript
  • 6,039
  • 3
  • 28
  • 43
1

Declared 3 variables (see: Declaring Multiple Variables in JavaScript).

var line = {}  // creates an empty object literal
    lines = [] // creates an empty array literal
    hasmore    // creates an empty undefined variable, which can hold any datatype
Community
  • 1
  • 1
Praveen
  • 55,303
  • 33
  • 133
  • 164
0

Go ahead and try this on your console :

var line = {}, lines = [], hasmore;

then access them you will see :

line is Object, 
lines is an array 
hasmore is undefined 
Ankit Tyagi
  • 2,381
  • 10
  • 19