ES6 Everyday: const Keyword

Starting off our week with one that’s pretty straightforward: the const keyword.

So, let’s say we have a constant value that we don’t want changed after assignment:

var appName = "The Fantastic Editor";
appName = "The TERRIBLE Editor";

console.log(appName); // The TERRIBLE Editor

We can use the const keyword to prevent reassignment:

const appName = "The Fantastic Editor";
appName = "The TERRIBLE Editor";

console.log(appName); // EXCEPTION: "appName is read-only"

Check it out for yourself in this ES6 Fiddle.

Resources