1. <i id='Oz4bw'><tr id='Oz4bw'><dt id='Oz4bw'><q id='Oz4bw'><span id='Oz4bw'><b id='Oz4bw'><form id='Oz4bw'><ins id='Oz4bw'></ins><ul id='Oz4bw'></ul><sub id='Oz4bw'></sub></form><legend id='Oz4bw'></legend><bdo id='Oz4bw'><pre id='Oz4bw'><center id='Oz4bw'></center></pre></bdo></b><th id='Oz4bw'></th></span></q></dt></tr></i><div id='Oz4bw'><tfoot id='Oz4bw'></tfoot><dl id='Oz4bw'><fieldset id='Oz4bw'></fieldset></dl></div>
    2. <small id='Oz4bw'></small><noframes id='Oz4bw'>

      <legend id='Oz4bw'><style id='Oz4bw'><dir id='Oz4bw'><q id='Oz4bw'></q></dir></style></legend>
        <bdo id='Oz4bw'></bdo><ul id='Oz4bw'></ul>
    3. <tfoot id='Oz4bw'></tfoot>

      你可以在 JavaScript 中使用常量变量吗?

      时间:2024-04-20
      <tfoot id='BSlXr'></tfoot>

      <small id='BSlXr'></small><noframes id='BSlXr'>

    4. <legend id='BSlXr'><style id='BSlXr'><dir id='BSlXr'><q id='BSlXr'></q></dir></style></legend>
            <tbody id='BSlXr'></tbody>
          1. <i id='BSlXr'><tr id='BSlXr'><dt id='BSlXr'><q id='BSlXr'><span id='BSlXr'><b id='BSlXr'><form id='BSlXr'><ins id='BSlXr'></ins><ul id='BSlXr'></ul><sub id='BSlXr'></sub></form><legend id='BSlXr'></legend><bdo id='BSlXr'><pre id='BSlXr'><center id='BSlXr'></center></pre></bdo></b><th id='BSlXr'></th></span></q></dt></tr></i><div id='BSlXr'><tfoot id='BSlXr'></tfoot><dl id='BSlXr'><fieldset id='BSlXr'></fieldset></dl></div>

              <bdo id='BSlXr'></bdo><ul id='BSlXr'></ul>

                本文介绍了你可以在 JavaScript 中使用常量变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在一个网站上读到,您可以在 JavaScript 中创建 constant 变量,例如:

                I read on one site that you can make constant variables in JavaScript like:

                const x = 20;
                

                但在另一个网站上我读到你不能.所以我现在很困惑,现在是什么?

                but on another site I read that you can't. So I am confused now what is it now?

                同样在 Visual Studio 2010 中,当我编写 const 时,它会在 JavaScript 文件中加下划线并显示语法错误.

                Also in Visual Studio 2010 when I write const it underlines it in the JavaScript file and shows syntax error.

                推荐答案

                const 是 ECMAScript Harmony 的一项提议功能(与正确的块范围 let 一起,它应该替换 var 和隐式全局变量).ECMAScript Harmony 是 ECMAScript 下一版本的灵感来源.

                const is a proposed feature of ECMAScript Harmony (together with a properly block-scoped let it is supposed to replace var and implicit globals). ECMAScript Harmony is a grab-bag of ideas for the next versions of ECMAScript.

                const 也是 ECMAScript 4 的一部分.

                const was also a part of ECMAScript 4.

                ECMAScript 4 从未发布过,也永远不会发布,ECMAScript Harmony 只会在几年后发布.因此,您不能可靠地使用它.

                ECMAScript 4 was never released and never will be, and ECMAScript Harmony will only be released in a couple of years. Therefore, you cannot reliably use it.

                ECMAScript 的一些实现或派生类实现了 const(例如 ActionScript).还有一些实现接受 const 作为 var 的同义词(IOW,你可以使用 const,但它不会给你任何保护.)

                There are some implementations or derivatives of ECMAScript that implement const (ActionScript, for example). There are also some implementations that accept const as a synonym for var (IOW, you can use const, but it won't give you any protection.)

                但是,除非您绝对可以保证您的代码只能在非常特定的 ECMAScript 衍生版本的非常特定的实现的非常特定的版本上运行,否则最好避免使用它.(这真是太可惜了,因为 const 尤其是 let 是对 var 和隐式全局变量的巨大 改进.)

                However, unless you absolutely can guarantee that your code will only run on very specific versions of very specific implementations of very specific derivatives of ECMAScript, it's probably better to avoid it. (Which is a real shame, because const and especially let are a huge improvement over var and implicit globals.)

                这篇关于你可以在 JavaScript 中使用常量变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 JavaScript 中使函数参数保持不变? 下一篇:在Javascript中有条件地初始化一个常量

                相关文章

                  <bdo id='kRTzl'></bdo><ul id='kRTzl'></ul>
                1. <legend id='kRTzl'><style id='kRTzl'><dir id='kRTzl'><q id='kRTzl'></q></dir></style></legend>
                2. <small id='kRTzl'></small><noframes id='kRTzl'>

                  1. <i id='kRTzl'><tr id='kRTzl'><dt id='kRTzl'><q id='kRTzl'><span id='kRTzl'><b id='kRTzl'><form id='kRTzl'><ins id='kRTzl'></ins><ul id='kRTzl'></ul><sub id='kRTzl'></sub></form><legend id='kRTzl'></legend><bdo id='kRTzl'><pre id='kRTzl'><center id='kRTzl'></center></pre></bdo></b><th id='kRTzl'></th></span></q></dt></tr></i><div id='kRTzl'><tfoot id='kRTzl'></tfoot><dl id='kRTzl'><fieldset id='kRTzl'></fieldset></dl></div>
                    <tfoot id='kRTzl'></tfoot>