You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/04-variables/article.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,7 @@ let message = 'Hello';
64
64
```
65
65
66
66
Some people also define multiple variables in this multiline style:
67
+
67
68
```js no-beautify
68
69
let user ='John',
69
70
age =25,
@@ -103,6 +104,7 @@ For instance, the variable `message` can be imagined as a box labeled `"message"
103
104
We can put any value in the box.
104
105
105
106
We can also change it as many times as we want:
107
+
106
108
```js run
107
109
let message;
108
110
@@ -149,11 +151,11 @@ So, we should declare a variable once and then refer to it without `let`.
149
151
````
150
152
151
153
```smart header="Functional languages"
152
-
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
154
+
It's interesting to note that there exist so-called [pure functional](https://en.wikipedia.org/wiki/Purely_functional_programming) programming languages, such as [Haskell](https://en.wikipedia.org/wiki/Haskell), that forbid changing variable values.
153
155
154
156
In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one.
155
157
156
-
Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits. Studying such a language (even if you're not planning to use it soon) is recommended to broaden the mind.
158
+
Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits.
157
159
```
158
160
159
161
## Variable naming [#variable-naming]
@@ -192,11 +194,11 @@ let my-name; // hyphens '-' aren't allowed in the name
192
194
```
193
195
194
196
```smart header="Case matters"
195
-
Variables named `apple` and `AppLE` are two different variables.
197
+
Variables named `apple` and `APPLE` are two different variables.
196
198
```
197
199
198
200
````smart header="Non-Latin letters are allowed, but not recommended"
199
-
It is possible to use any language, including cyrillic letters or even hieroglyphs, like this:
201
+
It is possible to use any language, including cyrillic letters, Chinese logograms and so on, like this:
When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and clearly communicate that fact to everyone.
262
264
263
-
264
265
### Uppercase constants
265
266
266
267
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
@@ -291,13 +292,14 @@ When should we use capitals for a constant and when should we name it normally?
291
292
Being a "constant" just means that a variable's value never changes. But there are constants that are known prior to execution (like a hexadecimal value for red) and there are constants that are *calculated* in run-time, during the execution, but do not change after their initial assignment.
292
293
293
294
For instance:
295
+
294
296
```js
295
297
const pageLoadTime = /* time taken by a webpage to load */;
296
298
```
297
299
298
300
The value of `pageLoadTime` is not known prior to the page load, so it's named normally. But it's still a constant because it doesn't change after assignment.
299
301
300
-
In other words, capital-named constants are only used as aliases for "hard-coded" values.
302
+
In other words, capital-named constants are only used as aliases for "hard-coded" values.
0 commit comments