批改状态:合格
老师批语:
*函数的参数和返回值
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>函数的参数与返回值</title></head><body><script>// 常规参数let fn = (a, b) => a + b;console.log(fn(1, 5));// 参数不足 给参数默认值let f = (a, b = 1) => a * b;console.log(f(5));// 参数过多,用...arr接收f = (a, b, ...c) => console.log(a, b, c);console.log(f(1, 2, 3, 4, 5, 6));let arr = [1, 2, 3, 4, 5, 6];console.log(...arr);//返回多个值用数组或对象//数组let fnn = () => [1, 2, 3, 4];console.log(fnn());//对象fnnn = () => ({id: 1,name: "张老师",age: 33,});console.log(fnnn());</script></body></html>

*模板字面量与模板函数
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>模板字面量和模板函数</title></head><body><script>//用反引号表示模板字面量 支持在在字符串中插入变量和表达式 插值console.log(`Hello world`);let name = "张老师";console.log(`Hello` + name);//也可以如下 用‘${xxxx}’表示占位符console.log(`Hello ${name}`);//也可以用表达式let age = 1;console.log(`${age ? `男:${name}` : `女`}`);//模板函数,用模板字面量当参数时 就是模板函数price`数量:${20}单价:${50}`;function price(strings, ...args) {console.log(strings);console.log(args);console.log(`总价:${args[0] * args[1]}元`);}</script></body></html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号