Blogger Information
Blog 12
fans 0
comment 0
visits 3578
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示四种常用的函数类型 和 实际演示原始数据类型与引用类型
len
Original
208 people have browsed it

实例演示四种常用的函数类型

  1. <script>
  2. // 命名函数
  3. let r = 8;
  4. const PI = 3.14;
  5. console.log(square(r));
  6. function square(radio) {
  7. return (
  8. `命名函数计算半径为${radio}cm 的圆形面积为 ` +
  9. PI * radio * radio +
  10. ` cm^2`
  11. );
  12. }
  13. // 匿名函数
  14. let square1 = function (r) {
  15. return `匿名函数计算半径为${r}cm 的圆形面积为 ` + PI * r * r + ` cm^2`;
  16. };
  17. console.log(square1(5));
  18. // 箭头函数
  19. let square2 = (r) => {
  20. return `箭头函数计算半径为${r}cm 的圆形面积为 ` + PI * r * r + ` cm^2`;
  21. };
  22. console.log(square2(9));
  23. // 立即执行函数
  24. let square3 = (function () {
  25. return (
  26. `立即执行函数计算半径为${r}cm 的圆形面积为 ` + PI * r * r + ` cm^2`
  27. );
  28. })(12);
  29. console.log(square3);
  30. </script>

实际演示原始数据类型与引用类型

  1. let uname = "mike";
  2. let age = 28;
  3. let gender = null;
  4. let mail;
  5. let student = [uname, age, gender, mail];
  6. console.table(student);
  7. let workmate = { name: uname, age: age, gender: gender, mail: mail };
  8. console.dir(workmate);
  9. let ismale = workmate.gender == "male";
  10. console.log(
  11. workmate.name +
  12. "'s age is " +
  13. workmate["age"] +
  14. ". gender is male? " +
  15. ismale
  16. );
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