
批改狀態(tài):合格
老師批語:
// 1.四種常見函數(shù)類型
//1.命名函數(shù)
function QQQ(a, b) {
return `${a}+${b}=` + (a + b); //模版字面量,支持表達式
}
console.log(QQQ(1, 2));
//2.匿名函數(shù)
const ssj = function (a, b) {
return `${a}+${b}=` + (a + b);
};
console.log(ssj(2, 2));
//3.立即執(zhí)行函數(shù)IIFE
let resull = (function (a, b) {
return `${a}+${b}=` + (a + b);
})(3, 5);
console.log(resull);
//4.箭頭函數(shù)(箭頭函數(shù)沒有自己的this)
//單參數(shù)可省()
let a123 = a => a + a; //只有一個返回值時可省{}
console.log(a123(22));
//無參或多參
let a1234 = () => 5 * 5;
console.log(a1234());
// 2.原始數(shù)據類型:
`string`, `number`, `boolean`, `null`, `undefined`;
// 引用數(shù)據類型:
`array`, `object`, `function`;
const arr = [10, "admin", true]; //數(shù)組
console.log(arr[2]);
let user = { id: 100, uname: "admin" }; //對象
console.log(user.uname); //如果屬性都是合法標識符,可用‘.’來訪問成員,不是的只能用[]
//函數(shù)是對象,所以可以添加屬性
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號