Tip 1 | Signal Unchanging Values with const |
In this tip, you’ll learn to use const to avoid reassignment and signal your intention to other developers.
Modern JavaScript introduced several new variable declarations, which is great. But it also introduced a new problem: Which variable declaration should be the default? And when should we use another type?
In the past, you had only one option for non-global variable assignment: var. Now there are many different options—var, let, and const—and each one has an appropriate usage. Try and keep things simple. In most cases, const is the best choice, not because it allows you to do the most, but because it lets you do the least. It has restrictions that make your code more readable.
Get Simplifying JavaScript 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.