变量与对象的区别
那么我们在描述,研究这个语言的时候就会牵扯到这几个问题.
值和对象 :
- var obj={};
- var num=9;
- var str='string'
- var arr=[];
很明显上面的几个变量都是一个对象,那变量一定是对象吗 ?
- var foo;
var foo;
foo是一个变量,但是foo不是对象.对象有个事实上 的特征就是,对象一定有成员 (属性或方法). //全文:http://www.iteye.com/topic/206218
foo就没有任何成员,他的值是undefined ,而undefined 的定义是:
undefined is a property of the global object, i.e. it is a variable in global scope.
The initial value of undefined is the primitive value undefined.
undefined 属性是 Global 对象的一个成员,该属性在脚本引擎初始化后可用。如果已声明了一个变量但还没有初始化,那么该变量的值就是 undefined。
The initial value of undefined is the primitive value undefined.
undefined 属性是 Global 对象的一个成员,该属性在脚本引擎初始化后可用。如果已声明了一个变量但还没有初始化,那么该变量的值就是 undefined。