Blogger Information
Blog 62
fans 3
comment 1
visits 29570
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS变量/常量/作用域之间的关系
kiraseo_wwwkiraercom
Original
286 people have browsed it

JS变量/常量/作用域之间的关系

变量,常量的声明与初始化

  1. // 变量 let
  2. let a = 'kira';
  3. console.log(a);
  4. // 常量
  5. const APP_KIRA= 'PHP中网';
  6. console.log(APP_KIRA);

效果图

作用域

  1. //1.块作用域
  2. {
  3. //代码段/代码块
  4. let a = 'php中文网';
  5. console.log(a);
  6. }
  7. // 函数作用域
  8. function chufa(a , b){
  9. // 函数内声明的变量 私有变量/局部变量
  10. let res = a / b;
  11. return res;
  12. }
  13. console.log(chufa(10 , 40));

效果图

标识符书写基本规则

  1. et $user = 111;
  2. console.log($user);
  3. let user_name = 'my name is 蛇形命名法';
  4. console.log(user_name);
  5. let UserName = 'my name is 大驼峰';
  6. console.log(UserName);
  7. const APP_USER = 'KIRA管理员';
  8. console.log(APP_USER);

效果图

JS函数写法如下

  1. function sum(a , b){
  2. return a + b;
  3. }
  4. console.log(sum(10 ,20));
  5. let jianfa = function(a , b){
  6. return a - b ;
  7. }
  8. console.log(jianfa(10 ,20));
  9. getChengFa = (a , b) =>{
  10. return a * b ;
  11. };
  12. console.log(getChengFa(10 ,20));

效果图

完整页面代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>JS变量/常量/作用域之间的关系</title>
  8. </head>
  9. <body>
  10. 1. 变量,常量的声明与初始化
  11. 2. 作用域
  12. 3. 写出合法标识符的基本规则,并实例演示
  13. 4. 实例演示最常用 的三种函数类型
  14. <script>
  15. // 1. 实例演示变量,常量的声明与初始化,使用方法
  16. // 变量 let
  17. let a = 'kira';
  18. console.log(a);
  19. // 常量
  20. const APP_KIRA= 'PHP中网';
  21. console.log(APP_KIRA);
  22. // 作用域
  23. //1.块作用域
  24. {
  25. let a = 'php中文网';
  26. console.log(a);
  27. }
  28. // 函数作用域
  29. function chufa(a , b){
  30. let res = a / b;
  31. return res;
  32. }
  33. console.log(chufa(10 , 40));
  34. // 标识符书写基本规则
  35. let $user =111;
  36. console.log($user);
  37. let user_name = 'my name is 蛇形命名法';
  38. console.log(user_name);
  39. let UserName = 'my name is 大驼峰';
  40. console.log(UserName);
  41. const APP_USER = 'KIRA管理员';
  42. console.log(APP_USER);
  43. // JS函数写法如下
  44. function sum(a , b){
  45. return a + b;
  46. }
  47. console.log(sum(10 ,20));
  48. let jianfa = function(a , b){
  49. return a - b ;
  50. }
  51. console.log(jianfa(10 ,20));
  52. getChengFa = (a , b) =>{
  53. return a * b ;
  54. };
  55. console.log(getChengFa(10 ,20));
  56. </script>
  57. </body>
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