A.2. Rethinking variables with ES2015
Strictly speaking, you’re free to keep using var whenever you want. Declaring variables this way has worked for as long as JS has been in existence, and it’s not changing anytime soon.
A.2.1. Variable declaration with let
ES2015 brings us two more ways to declare your variables: let and const. In terms of usage, not much has changed—things are just a bit stricter and a little saner. With let, you may declare your variables, just as you always have with var:
var x = 5; // old way let x = 5; // new way
The difference between let and var is a matter of scope. Variable declarations made with let are a bit more familiar to users of other programming languages. The variables will exist only in the block they ...
Get Web Components in Action now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.