Blogger Information
Blog 34
fans 0
comment 0
visits 24477
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript-基础(二)
CY明月归
Original
350 people have browsed it

1. 实例演示函数参数与返回值

  1. // 1. 参数不足: 默认参数
  2. f0 = (a=0,b=0)=>console.log(a+b)
  3. f0(1)
  4. f0(1,4,1)
  5. // 2. 参数过多: ...剩余参数
  6. f1 = (a,b,...c)=>console.log(a,b,c)
  7. f1(1,2,3,4,5,6,7,8,9,0)
  8. arr1 = [1,2,3,4,5,6,7,8]
  9. f2 = ()=>console.log(...arr1)
  10. //...arr打散
  11. f2()
  12. //等价于
  13. f2(0,1,2,3,4,5,6,7)
  14. f3 = (...arr)=>arr.reduce((a,b)=>(a+b))
  15. console.log(f3(1,2,3,44,5,6,7,88,99,0))
  16. // 返回值: 函数只能有一个返回值,默认单值返回
  17. // 需要返回多个值==>数组,对象
  18. // 本质 上仍然返回一个值,只不过这是一个引用类型的复合
  19. let f4 = () => [1, 2, 3, 4, 5];
  20. let res = f4();
  21. console.log(res);

2. 实例演示模板字面量与模板函数

!模板字面量也叫模板函数

  1. let str1 = 'hello 123'
  2. let str2 = `hello zy`
  3. console.log(`say hello: ${str2}`)
  4. function modelf(name){
  5. return alert(`hello: ${name}`)
  6. }
  7. //modelf('佐罗')
  8. function calc(a,...b){
  9. console.log(a)
  10. console.log(b)
  11. }
  12. // 模板函数的参数:
  13. // 第一个参数: 模板字面量中的"字符串字面晨"
  14. // 第二个参数: 模板字面量中的"插值"数组
  15. calc `数量: ${10} 单价: ${500} 发货地:${'上海'} 健康码:${'green'}`;
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post