1:鍵值打印
let num = {
age:'123',
name:'joe',
height:'196'
}
console.log({num}); //變量包裝求类,可以同時打印出變量名和變量值
*可以打印出屬性名和值笤闯,便于在復(fù)雜的業(yè)務(wù)中找到打印結(jié)果
2.&& ?? ?.
//1.&&
let num = 6
//if(num > 5){console.log('執(zhí)行')}
//簡化后:
num > 5 && console.log('執(zhí)行');
//2.??
let obj = {
value:null
}
let objs = obj.value ?? '100'
//*null值判斷符真朗,當(dāng)左邊為null或者為undefined才返回右邊的值
//3.?.
let street = user.address && user.address.street;
//簡化后:
let street = user.address?.street;
//*?.也叫鏈式判斷運算符,逐層判斷左邊是否為null或者undefined,如果是就不在繼續(xù)往下運算阁猜,如果不是則返回右邊的值
3.includes
let arrays = [8,9,10,11]
let num = 8
if(arrays.includes(num)){
console.log('ok');
}
//*如果數(shù)組中存在我想查詢的值,則執(zhí)行后面的步驟
4.字符串轉(zhuǎn)為數(shù)字
let num = '44'
console.log(+num)
5.對象:object.hasOwn
let obj = {
name:'join',
age:'16'
}
console.log(Object.hasOwn(obj,'name'));
//*查詢對象中是否有某個鍵蹋艺,有則返回true
6..at
let arr = [1,2,3,4]
console.log(arr.at(-1));
console.log(arr.at(0))
//*查詢數(shù)組中某一項下標的值剃袍,-1是最后一位,0是第一位