Javascript变量定义 - 澄清

时间:2013-11-27 04:45:26

标签: javascript variables declaration

以下声明是什么意思?

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

我知道lines = []是一个数组,但我不了解其他数据。

实际代码是使用javascript xpcom

逐行读取文件
var line = {}, lines = [], hasmore;
do {
      hasmore = istream.readLine(line);
      lines.push(line.value); 
} while(hasmore);

3 个答案:

答案 0 :(得分:4)

它正在创建3个变量

var line = {};   // creates an object
var lines = [];  // creates an array
var hasmore;     // undefined

答案 1 :(得分:1)

声明了3个变量(参见: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

答案 2 :(得分:0)

继续在您的控制台上尝试:

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

然后访问它们你会看到:

line is Object, 
lines is an array 
hasmore is undefined