Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does @const mean in JavaScript?

Tags:

People also ask

What does const {} mean in JavaScript?

In JavaScript, `const` means that the identifier can't be reassigned. (Not to be confused with immutable values. Unlike true immutable datatypes such as those produced by Immutable.

Should I use let or const?

As a general rule, you should always declare variables with const, if you realize that the value of the variable needs to change, go back and change it to let. Use let when you know that the value of a variable will change. Use const for every other variable.

Can we change const value in JavaScript?

The property of a const object can be change but it cannot be change to reference to the new object.


We are considering adopting the Google JavaScript coding guidelines within our company to maintain consistency across projects but one thing is confusing me. In the section on constants it says to use the @const keyword annotation for compile-time constant enforcement but I have never come across the @ symbol before. Is this a Google extension or part of the core language?

Here is the full text:

For non-primitives, use the @const annotation.

/**   * The number of seconds in each of the given units.   * @type {Object.<number>}   * @const   */ goog.example.SECONDS_TABLE = {     minute: 60,   hour: 60 * 60   day: 60   * 60 * 24 } 

This allows the compiler to enforce constant-ness.

As for the const keyword, Internet Explorer doesn't parse it, so don't use it.