Blogger Information
Blog 28
fans 0
comment 0
visits 11767
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11.1日作业
子墨吖ฅฅ
Original
332 people have browsed it
  1. const USER_NAME = "啊墨"; //常量
  2. console.log(USER_NAME);
  3. let userName = "子墨"; //变量
  4. console.log("hello" + userName);
  5. // 命名函数
  6. function sayHello(name) {
  7. return "你好啊"+ name
  8. }
  9. console.log(sayHello(userName));
  10. // 匿名函数
  11. const sayHello1 = function (name) {
  12. return "你好啊"+ name
  13. }
  14. console.log(sayHello1(userName));
  15. // 箭头函数
  16. const sayHello2 = (name) =>{ return "你好啊"+ name}
  17. console.log(sayHello2(userName));
  18. // 立即执行函数
  19. const sayHello3 =(function sayHello3(name) {
  20. console.log("你好啊"+ name);
  21. })(userName);
  22. // ---------------
  23. // 1.允许重复变量的声明
  24. var x = 1;
  25. var x = 2;
  26. var x = 3;
  27. var x = 5;
  28. console.log(x);// 可以看到输出的x是5 原始数据被覆盖
  29. // 2.局部变量挂载到全局对象,造成全局对象的污染 (变量提升)
  30. // 在函数内定义的变量是局部变量,而在函数之外定义的变量称为外部变量,外部变量是全局变量
  31. function add(a) {
  32. for(var v = 0;v < 5;v++){
  33. //在循环体内输出v
  34. console.log(v);
  35. }
  36. //在循环体外输出v
  37. console.log(v)
  38. }
  39. add(1)
  40. // 3.未声明即可使用
  41. function foo() {
  42. console.log(y); // => undefined
  43. var y= 1;
  44. console.log(y); // => 1
  45. }
  46. foo()

运行效果图

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