What is the output of following code?
var a = 6;
let a = 8;
console.log(a);
----o----
let
was introduced in ES6 and is used to declare variables in JavaScript. If a variable with the same name is already declared in the same scope, let
throws an error. Here second line throws below error:
Uncaught SyntaxError: Identifier 'a' has already been declared
This behaviour is explained here in ECMAScript.