基本的数据类型
number
-整数
- 15
- 0377(八进制) e.g.var num = 070; //56
- 0xff (十六进制)e.g. var num = oxA; //10
-浮点数
- 1.2
- 1.4E2 (科学计数法)
e.g. var num = 2.34e2; //234
var num = 2.34e-2; //0.0234
- 特殊值
- NaN (not a number)
- Infinity (无穷大(有正无穷大和负无穷大)) e.g. var num = 1/0; //infinity
String
由单引号或者双引号引起来的内容
var name = ’kuckboy’;
var name = “kuckboy”;
var num = ‘2.12’;
Boolean
true
false
必须是小写
var sex = ture;
if (sex){
...
} else {
...
}
Object
Object是一组无序的名值对的集合
var cat = {
name:’kitty’,
age:2,
mew:function(){
console.log(‘miao~’);
}
}
var dog = new object();
Null
类型说明
- 值:null
出现的场景
- 表示对象不存在
var car = null;
Undefined
值
- undefined
出现的场景
- 以声明未赋值的变量
e.g. var a; console.log(a); //undefined
- 获取对象不存在的属性
e.g. var obj = {a:1,b:2}; console.log(c); //undefined
类型的识别
typeof
var num;
typeof num; //undefined
var num = 1;
typeof num; //number
var num = ‘1’;
typeof num; //string
var flag = true;
typeof flag; //boolean
var cat = null;
typeof cat; //object
var cat = {name:’kitty’};
typeof cat; //object
原始类型和引用类型
number
string
boolean
undefined
null
object(引用)
![](https://images2015.cnblogs.com/blog/707617/201608/707617-20160813103037843-1940320140.png)