5,321
edits
(→Enums) |
|||
Line 98: | Line 98: | ||
===<code>var</code> vs <code>let</code>, <code>const</code>=== | ===<code>var</code> vs <code>let</code>, <code>const</code>=== | ||
* <code>var</code> is the old way of declaring variables. It has function-scope rather than block-scope. Note that <code>var</code> can also be redefined | * <code>var</code> is the old way of declaring variables. It has function-scope rather than block-scope. Note that <code>var</code> can also be redefined which can hide errors. | ||
* <code>let</code> and <code>const</code> are post-ES6 ways which have block-scope. | * <code>let</code> and <code>const</code> are post-ES6 ways which have block-scope. | ||
These days you should never use <code>var< | These days you should never use <code>var<c/ode>. | ||
The Google [https://google.github.io/styleguide/jsguide.html JS Style Guide] and [https://google.github.io/styleguide/tsguide.html TS Style Guide] suggest using <code>const</code> by default. | The Google [https://google.github.io/styleguide/jsguide.html JS Style Guide] and [https://google.github.io/styleguide/tsguide.html TS Style Guide] suggest using <code>const</code> by default. | ||