Blogger Information
Blog 47
fans 0
comment 3
visits 44715
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Javascript中的变量与常量
江流
Original
468 people have browsed it

变量与常量常量的区别

  1. 声明:变量使用let,常量使用const
  2. 初始化:变量人初始化可以与声明分别进行,先声明,再初始化; 常量的声明和初始化必须同时进行。
  3. 可修改性:变量的值可以修改、更新;常量不能修改。
  4. 命名:变量一般使用驼峰命名方式;常量一般使用蛇形命名方式。

    举例

    1. // 声明变量
    2. let userName;
    3. // 初始化变量
    4. userName = "Tom";
    5. console.log(userName);
    6. // 更新变量值
    7. userName = "Tomast";
    8. // 声明并初始化常量
    9. const PI = 3.14;
    10. console.log(userName);
    11. console.log(PI);
    12. // 修改常量值,产生错误
    13. PI = 314159;

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