Should "const" be favored over "let"?
Glen Huang
curvedmark at gmail.com
Fri Apr 17 12:35:10 UTC 2015
@Mathias
Thanks for the clarification. I should use "never rebind".
@Alex @Frankie
You guys are right. There won't be any performance gain since it's already statically analyzable.
FWIW, I opened a feature request on eslint concerning this coding style: https://github.com/eslint/eslint/issues/2333 <https://github.com/eslint/eslint/issues/2333>
> On Apr 17, 2015, at 8:17 PM, Mathias Bynens <mathiasb at opera.com> wrote:
>
> On Fri, Apr 17, 2015 at 7:53 AM, Glen Huang <curvedmark at gmail.com> wrote:
>> I've completely replaced "var" with "let" in my es 2015 code, but I noticed most variables I introduced never change.
>
> Note that `const` has nothing to do with the value of a variable
> changing or not. It can still change:
>
> const foo = {};
> foo.bar = 42; // does not throw
>
> `const` indicates the *binding* is constant, i.e. there will be no
> reassignments etc.
>
> In my post-ES6 code, I use `const` by default, falling back to `let`
> if I explicitly need rebinding. `var` is for legacy code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150417/5da53ae9/attachment.html>
More information about the es-discuss
mailing list