1.ECMAScript3中定义了变量可分为原始值和引用值。
原始值:是保存在栈(stack)中的简单数据段;也就是说他们的值是直接存储在变量访问的位置。
引用值:是保存在堆(heap)中的对象,也就是说,存储在变量处的值是一个指针(point),该指针地址->指向存储对象的内存处。
使用typeof判断变量的数据类型;如:
"use strict"; var a=3; alert(typeof a);//输出 number
JavaScript共5中简单数据基本类型(原始类型):
Undefined,Boolean,String,Null,Number
还有一个复杂类型Object类型(引用类型)说白了就是C语言中的结构体;就是对象实例化后都在堆中存储。
对于 alert(typeof null);则返回object引用类型;被认为null是对象的占位符。
注:typeof 是操作符;而不是函数。