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
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,7 +209,7 @@ let return = 5; // also can't name it "return", error!
209
209
210
210
````warn header="An assignment without `use strict`"
211
211
212
-
Normally, we need to define a variable before using it. But in the old times, it was technically possible to create a variable by a mere assignment of the value, without `let`. This still works now in if we don't put `use strict`, the behavior is kept for compatibility with old scripts.
212
+
Normally, we need to define a variable before using it. But in the old times, it was technically possible to create a variable by a mere assignment of the value, without `let`. This still works now if we don't put `use strict`, the behavior is kept for compatibility with old scripts.
213
213
214
214
```js run no-strict
215
215
// note: no "use strict" in this example
@@ -303,11 +303,11 @@ Please spend some time thinking about the right name for a variable before decla
303
303
Some good-to-follow rules are:
304
304
305
305
- Use human-readable names like `userName` or `shoppingCart`.
306
-
- Stay away from abbreviations or short names `a`, `b`, `c`, unless you really know what you're doing.
306
+
- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing.
307
307
- Make the name maximally descriptive and concise. Examples of bad names are `data` and `value`. Such a name says nothing. It is only ok to use them if it's exceptionally obvious from the context which data or value is meant.
308
308
- Agree on terms within the team and in your own mind. If a site visitor is called a "user" then we should name related variables like `currentUser` or `newUser`, but not `currentVisitor` or a `newManInTown`.
309
309
310
-
Sounds simple? Indeed it is. But creating good descriptive-and-concise names in practice is not. Go for it.
310
+
Sounds simple? Indeed it is, but creating good descriptive-and-concise names in practice is not. Go for it.
311
311
312
312
```smart header="Reuse or create?"
313
313
And the last note. There are some lazy programmers who, instead of declaring a new variable, tend to reuse the existing ones.
@@ -327,6 +327,6 @@ We can declare variables to store data. That can be done using `var` or `let` or
327
327
328
328
- `let` -- is a modern variable declaration. The code must be in strict mode to use `let` in Chrome (V8).
329
329
- `var` -- is an old-school variable declaration. Normally we don't use it at all, but we'll cover subtle differences from `let` in the chapter <info:var>, just in case if you'll need them.
330
-
- `const` -- is like `let`, but the variable can't be changed.
330
+
- `const` -- is like `let`, but the value of variable can't be changed.
331
331
332
332
Variables should be named in a way that allows to easily understand what's inside.
0 commit comments