kuskmen kuskmen - 2 years ago 81
Javascript Question

Declare variable "let" in javascript ECMAScript6

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download