1.类型判断
let a = []
let b = {}
console.log(typeof a) //obj
console.log(typeof b) //obj
//当前数组和对象都返回 obj
//用另一种判断类型的方法(通过 原型链进行判断,判断对象的prototype属性是都在原型链上)
console.log(a instanceof Array) //true
console.log(b instanceof Object) //true
console.log(b instanceof Array) //false
2.标签模板
let a = kolento;
let b = Amiee;
console.log(tag`你好,我叫${Kolento},她是${Amiee}`);
function tag(string,kol,ami){
console.log(srting) //['你好,我叫',',她是'] 打印非变量的字符串构成的数组
console.log(kol);kolento
console.log(ami);//amiee
}
也可以把变量全搜集在一起
function test(string,...all){
console.log(all) //['kolento','amiee']
}
let c = 'world';
console.log(hello`${c}`)
function hello(string){
console.log(string) //['',''];在hello字符串的前后也有空字符串打印出来
}
网友评论