简单数据类型
(Number,String,Boolean,Underfined,Null)
复杂数据类型
object
浅拷贝
let a=[0,1,2,3,4],
b=a;
console.log(a===b);
a[0]=1;
console.log(a,b);
深拷贝json
var test={
a:"ss",
b:"dd",
c:[
{dd:"css",ee:"cdd"},
{mm:"ff",nn:"ee"}
]
};
var test1 = JSON.parse(JSON.stringify(test));
console.log(test);
console.log(test1);
test1.c[0].dd="change"; //改变test1
console.log(test); //不影响test
console.log(test1);
————————————————
递归
function dg(num){
if(num <= 0){
return 0;
}else{
return num + dg(num -1) //要有判断条件否则会报错
}
}
console.log(dg(5)) // 15 dg(5)=5+4+3+2+1
数组解构
// 解构:
let arr = [1,2,3,4]
let [a,b,c,d] = arr
console.log(a,b,c,d);