Why using “const” construction in JavaScript is a bad practice?
-
31-05-2021 - |
Question
In Google Style guide for JavaScript written (prove link), that using a "const" construction is a bad practice, why?
Solution
Because it is not standard (yet). It's a JavaScript 1.5 keyword, not ECMAScript. From the MDN documentation:
The current implementation of
const
is a Mozilla-specific extension and is not part of ECMAScript 5. It is supported in Firefox & Chrome (V8) and partially supported in Opera 9+ and Safari. It is not supported in Internet Explorer 6-9, or in the preview of Internet Explorer 10. Theconst
keyword currently declares the constant in the function scope (like variables declared with var).
Also if you read the section you linked to carefully, the last sentence is:
As for the
const
keyword, Internet Explorer doesn't parse it, so don't use it.