Blogger Information
Blog 38
fans 0
comment 0
visits 18584
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示函数参数与返回值、演示模板字面量与模板函数
Blackeye
Original
324 people have browsed it

hw

  1. <script>
  2. // 1.实例演示函数参数与返回值
  3. // 1.参数不足:默认参数
  4. let add = (a,b) => {
  5. return a+b;
  6. }
  7. console.log(add(1,2));
  8. console.log(add(100));
  9. console.log("-----------------------------------------");
  10. let addN = (a,b=0) => {
  11. return a+b;
  12. }
  13. console.log(addN(1,2));
  14. console.log(addN(100));
  15. console.log("-----------------------------------------");
  16. // 2.参数过多(剩余参数)
  17. // ...rest:用在函数的形参中,归并
  18. // ...用在参数调用的实参中,是解包,打散
  19. let addRange = (...arr) => {
  20. let out = 0;
  21. for(let i=0;i<arr.length;i++){
  22. out += arr[i];
  23. }
  24. return out;
  25. }
  26. console.log(addRange(1,2,3,4,5,6,7,8,9,10));
  27. let addlist = [1,2,3,4,5,6,7,8,9,10];
  28. console.log(addRange(...addlist));
  29. // 返回值为一个值
  30. let say = ()=>"Hello php.cn";
  31. console.log(say());
  32. // 返回多个值
  33. let rangeOut = ()=>[1,2,3,4,5,6,7,8,9,10];
  34. console.log(rangeOut());
  35. let girlFriend = ()=>({
  36. name: "姑奶奶",
  37. age:18,
  38. gender:"female",
  39. habbit:"buy buy buy",
  40. getInfo(){
  41. return `${this.age}岁的${this.name},最大的爱好是${this.habbit}. :<`;
  42. }
  43. })
  44. console.log(girlFriend());
  45. console.log(girlFriend().getInfo());
  46. //2.实例演示模板字面量与模板函数
  47. let studentName = "Dave" ;
  48. //模板字面量
  49. let demo = `Hello ${studentName}`
  50. console.log(demo);
  51. //模板函数
  52. alert `Hello Dave`;
  53. </script>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!