批改状态:合格
老师批语:
//变量推荐用let声明,常量用const声明let username = '张三';console.log(username)// 变量值可以被更新、修改username = '李四';console.log(username);// 常量// 创建常量时,必须初始化const gender = '男'console.log(gender)//常量被声明后不能修改错误做法:const gender = '男'gender = "女"
//命名函数function f(a,b) {return `${a} * ${b} = ${a*b}`;}console.log(f(2,3))// 匿名函数let f2 = function (a,b){return `${a} * ${b} = ${a*b}`;}console.log(f2(3,4))// 箭头函数,匿名函数的简化// let 禁止重复声明,var可以// 1. 删除关键字 function// 2. 在(参数列表)与{代码块}之间用"胖箭头"(=>)let f3 = (a,b) => {return `${a} * ${b} = ${a*b}`;}console.log(f3(4,5))// 当参数不足时,使用默认参数f3 = (a,b=1) => {return `${a} * ${b} = ${a*b}`;}console.log(f3(6))//当函数参数只有一个时,括号可以不写f3 = uname =>{return `hello ${uname}`;}console.log(f3('php中文网'))//没有参数时 括号不能省略f3 = () => { return "hello world!"}console.log(f3())//函数体只有return一行代码 可以不写return ,大括号也要省略f3 = (a,b) => a*b;console.log(f3(7,8));//立即执行函数 IIFE//将声明和调用二合一,声明完成直接运行,将函数使用括号包起来使函数运行(function f4(a,b) { console.log(`${a} * ${b} = ${a*b}`) })(9,10);(function (a,b) { console.log(`${a} * ${b} = ${a*b}`) })(11,12);((a,b) => { console.log(`${a} * ${b} = ${a*b}`) })(13,14);((a,b) => console.log(`${a} * ${b} = ${a*b}`))(15,16);
// 数值型//不区分整数和小数,numberconsole.log(123,typeof 123)//字符串 ('xxx',"xxx",`xxx`) stringconsole.log("hi",typeof "hi")console.log('hello world')console.log("hello world")console.log(`hello world`)//布尔类型 true or false booleanconsole.log(true, typeof true)//null,空对象console.log(null, typeof null)//undefined, 未定义console.log(email)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号