5

Why is it possible to declare variable named let when I can't declare const or var. I know I will never do that , but I am just curious if there is reasonable explanation. So I can do:

var let = 5;
let x = 3;
x + let -> 8

Why is this even possible?

2
  • I don't think this is a wise code to write. I don't think that should be authorized. Working with babel and webpack: that doesn't work for me. Could you share your dev env? Commented Jun 17, 2016 at 9:45
  • @Damien Any browser console and node.js env Commented Jun 17, 2016 at 11:28

2 Answers 2

5

From the Mozilla Developer Network site under Future reserved keywords:

The following are only reserved when they are found in strict mode code:

which includes let.

However, const and var are listed under Reserved keywords as of ECMAScript 6 and this document shows the history where they were originally reserved in ECMAScript 1.

Strict Mode

To invoke strict mode for an entire script, put the exact statement "use strict"; (or 'use strict';) before any other statements.

What is strict mode?

ECMAScript 5's strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode isn't just a subset: it intentionally has different semantics from normal code. Browsers not supporting strict mode will run strict mode code with different behavior from browsers that do

Sign up to request clarification or add additional context in comments.

Comments

0

i think you can still write this in browser's console because the lately support ES6 and let may still not blocked to be defined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.