brings a lot of great features to the language, and one of those is . Constants sound simple enough, eh? ES6 JavaScript constants Well, many JS developers misunderstand them so… let’s walk through the feature (and more)! Constant? Constant what? Good question! In JavaScript, constants are constant in . reference Reference? Reference to what? A reference to a . value ‘hi’, 5, [], {} // all values However, it’s important to note that in the case of objects (and thus, arrays), the value is a reference to the object itself. So I just can’t change the value of a “constant”? . Sorta This calls for a quick lesson on types in JS. There are five primitive types: undefined, null, boolean, string, and number. Everything else is an object. Values, not variables, are first-class. And, as I mentioned earlier, the of an object is merely a reference. By design (long before ES6), all primitives are , and objects are . value immutable mutable Thus, when you “change” (at least, as it seems) the value of an immutable (i.e. ), you’re not actually mutating but instead it to an entirely new reference since is merely the process of creating said “reference”. ++ re-assigning assignment const num = 2;num++; // TypeError// is just short-hand for , clearly assignment ++ += Yet, since objects are mutable, you can change their value with or without re-assignment. const arr = [1, 2];arr.push(3); // [1, 2, 3]arr = [1, 2]; // SyntaxError (thus, value != reference) And, only re-assignment- is blocked by ES6 _const_ants since it deals with references, values. not What’s the benefit? Constants primarily benefit readability but may benefit performance as well. If you know a value won’t be replaced, you may know more about the intent of the program. eventually Rule of thumb- use unless you need re-assignment — in which case, you should most likely use to still reap the benefit of block-scope, but we’ll save that for another post. const let Use constants to step up code readability with minimal effort, but first, make sure you understand them! Just my 2¢. If you found this interesting, consider following me on and , where I share cool code and more. Twitter GitHub is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising & sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories