Monday, 20 February 2017

javascript - Is a let variable equal to a var variable?





If I have something like:



let x = 20;
var z = 20;



will



x === z

Answer



Try it out and see for yourself...



(If nothing is displayed that is because you are using a browser that doesn't support let.)






"use strict";

let x = 20;
var z = 20;

document.write(x === z);






Read this answer for details about the differences between let and var:




The difference is scoping. var is scoped to the nearest function block (or global if outside a function block), and let is scoped to the nearest enclosing block (or global if outside any block), which can be smaller than a function block.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...