let and const

Next, we'll move on to variable declarations in JavaScript. In addition to the original var cat = "meow"; syntax, ES2015 introduces two new forms for declaring different variables: let and const. We won't go into extreme detail on these and why they were specifically implemented, but the important things to note are things that will cause errors later on. For example, with let statements, let variables can never be redeclared in the same scope. You can, however, reassign the value in the variable:

let greeting = "hello";let greeting = "world"; // This will result in an error!greeting = "world"; // This will not!

const, on the other hand, makes it so you cannot reassign a variable. It does not make it immutable, mind you; it ...

Get Phoenix Web Development 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.