ES6中的const命令【轉】

來源:互聯網
上載者:User

標籤:log   使用   const   地址   post   mis   重複   初始化   initial   

1 const PI=3.1415;2 console.log(PI);//3.14153 4 PI=3;//Uncaught TypeError: Assignment to constant variable.

2.const一旦聲明常量,就必須立即初始化,不能留到以後賦值

1 const WIDTH;//Uncaught SyntaxError: Missing initializer in const declaration

3.const聲明的常量只在當前範圍內有效

1 if(true){2   const NAME=‘XG‘3 }4 5 console.log(NAME);//Uncaught ReferenceError: NAME is not defined

4.const聲明的常量不存在“聲明提前”,只能先聲明後使用

1 if(true){2   console.log(NAME);//Uncaught ReferenceError: NAME is not defined3   const NAME=‘XG‘;4 }

5.const不可重複聲明

6.const聲明的常量如果儲存的是參考型別的資料,只會保證該資料的地址不變,並不能保證該資料不變

轉載自:http://www.cnblogs.com/xgblogs/p/6142792.html

ES6中的const命令【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.