javascript - What is the diffrence between 'let' and 'const' ECMAScript 6? -


i'm wondering difference between let , const in ecmascript 6. mean both of them block scoped, example in following code:

const pi = 3.14; console.log(pi);  pi = 3; console.log(pi);  const pi = 4; console.log(pi);  var pi = 5; console.log(pi); 

in ecmascript 5 output be:

3.14 3.14 3.14 3.14 

but in ecmascript 6 be:

3.14 3 4 5 

i'm wondering why ecmascript 6 allows change of const value, question why should use 'const' now? can use 'let' instead?

note: jsbin can used testing, choose javascript run ecmascript 5 code , traceur run ecmascript 6 capabilities.

what you're seeing implementation mistake. according es6 spec wiki on const, const is:

a initialize-once, read-only thereafter binding form useful , has precedent in existing implementations, in form of const declarations.

it's meant read-only, is. es6 implementation of const in traceur , continuum buggy (they overlooked it)

here's github issue regarding traceur not implementing const


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -