Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Commit 23f0985

Browse files
committed
Add approach to "constants" in ES5
1 parent 31077a4 commit 23f0985

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

es5/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1. [Functions](#functions)
1515
1. [Properties](#properties)
1616
1. [Variables](#variables)
17+
1. [Constants](#constants)
1718
1. [Hoisting](#hoisting)
1819
1. [Comparison Operators & Equality](#comparison-operators--equality)
1920
1. [Blocks](#blocks)
@@ -367,7 +368,7 @@
367368
var superPower = new SuperPower();
368369
```
369370
370-
- Use single `var` declaration for multiple variables.
371+
- Use a single `var` declaration for multiple variables.
371372
Having one `var` declaration per variable is an unnecessary code repetition
372373
and it should hardly ever be a problem anyway as you always want to strive
373374
at simple functions with as few local variables as possible. If you need
@@ -479,6 +480,23 @@
479480
**[⬆ back to top](#table-of-contents)**
480481
481482
483+
## Constants
484+
485+
- JavaScript doesn't support a notion of constants so we resort to normal
486+
class variables in their absence. So to denote a variable is meant to be
487+
treated like a constant you should use the ALL_CAPS notation, e.g.:
488+
489+
```
490+
WHICH.MyClass.MY_CONSTANT = 'fooBar';
491+
```
492+
493+
Please note, it is still possible to assign a different value to this kind
494+
of variables so they should only be used as read-only properties. If you
495+
need to change their values, use a standard variables notation.
496+
497+
**[⬆ back to top](#table-of-contents)**
498+
499+
482500
## Hoisting
483501
484502
- Variable declarations get hoisted to the top of their scope, but their assignment does not.

0 commit comments

Comments
 (0)