4.1 变量
基本类型:简单数据段
Undefined,Null,Boolean,Number,String
引用类型:多个值构成的对象
1.1 动态的属性,我们不能给基本类型添加属性
function l(obj){
console.log(obj);
}
var person = new Object();
person.name = "nicolas";
l(person.name);//nicolas
var name = "nicolas";
name.age = 27;
l(name.age);//undefined
1.2 复制变量值
基本类型的复制:参与任何操作不受影响
引用类型复制:改变其中一个变量,就会影响另一个变量
var num1 = 5;
var num2 = num1;
num2++;
l(num1);//5
l(num2);//6
var obj1 = new Object();
var obj2 = obj1;
obj1.name = "nicolas";
l(obj2.name)//nicolas
1.3 传递参数(参数只能按值传递)
function addTen(num){
num += 10;
return num;
}
var count = 20;
var result = addTen(count);
l(count);//20
l(result);//30
1.4 检测类型
typeof 检测基本类型
function l(obj){
console.log(obj);
}
var s = "nocholas";
var b = true;
var i = 22;
var u;
var n = null;
var o = new Object();
l(typeof s);//string
l(typeof i);//number
l(typeof b);//boolean
l(typeof u);//undefined
l(typeof n);//object
l(typeof o);//object
instanceof(检测对象)
var person = {};
var colors = [];
var reg = /^$/;
l(person instanceof Object);//true
l(colors instanceof Array);//true
l(reg instanceof RegExp);//true