美文网首页
ES6 学习(const篇)

ES6 学习(const篇)

作者: 淡淡的真 | 来源:发表于2016-08-05 14:18 被阅读0次

    - const 命令

    ** 不允许重复声明
    const 用于声明常量,一旦声明,其值就不能改变
    const 一旦声明常量,就必须立即赋值 **

    const 是常量索引,不是值所以复合类型变量的值是可变的

    const A = 1;
    A = 2;    // A is read-only
    
    const B = {
      name : "java"
    }
    B.name = "javascript";
    console.log(B.name);  // "javascript"
    

    const 只会在块级作用域有效

    if(true){
      const A = 1;
    }
    A // A is not defind
    

    跨模块常量

    - -app.js
    const A = 1;
    const B = 2;
    export {A, B}
    
    -- main.js
    import {A, B} from './app.js'
    console.log(A, B);    //  1  2
    

    相关文章

      网友评论

          本文标题:ES6 学习(const篇)

          本文链接:https://www.haomeiwen.com/subject/fzbhsttx.html