6.21
函数的使用
function fn(name){
var a = name || 'zs'
console.log(a);
}
fn('ls')
fn('')
fn(true)
fn(false)
fn(null)
fn(undefined)
fn(0)
fn({id : 1})
fn([1,2])
function fn_1(name = 'zs'){
console.log(name);
}
fn_1()
fn_1('ls')
function fn_2(x,...rest){
console.log(x);
console.log(arguments[1]);
console.log(rest);
}
fn_2(1,2,3,4,5)
扩展运算符
let arr = [1, 2, 3, 4, 5]
console.log(...arr);
let arr_1 = [...arr, 6, 7, ...arr]
console.log(arr_1);
let arr_2 = arr
arr_2[0] = 9
console.log(arr)
console.log(arr_2);
let arr_3 = [...arr]
arr_3[0] = 6
console.log(arr);
console.log(arr_3);
var arr_4 = ['y','z','m','n']
var [x,...arr_4] = arr
let[x,y,z,m,n] = [...arr]
console.log(x,y,z,m,n);
console.log(arr_4);
var arr_5 = [1,2,3]
function fn(x,y,z){
console.log(x,y,z);
}
fn(...arr_5)
var str = '将伪数组转化成真正的数组'
console.log([...str]);
var obj = {
a:1,
b:2,
c:3
}
console.log({...obj});
var obj_1 = {...obj}
obj_1.a = 7
console.log(obj);
console.log(obj_1);
var obj = {
a:1,
b:2,
c:3
}
var obj_1 = {
a:4,
e:8,
...obj,
}
console.log(obj_1);