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
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,16 +88,16 @@ In older scripts, you may also find another keyword: `var` instead of `let`:
88
88
*!*var*/!* message ='Hello';
89
89
```
90
90
91
-
The `var` keyword is *almost* the same as `let`. It also declares a variable, but in a slightly different, "old-school" way.
91
+
The `var` keyword is *almost* the same as `let`. It also declares a variable but in a slightly different, "old-school" way.
92
92
93
-
There are subtle differences between `let` and `var`, but they do not matter for us yet. We'll cover them in detail in the chapter <info:var>.
93
+
There are subtle differences between `let` and `var`, but they do not matter to us yet. We'll cover them in detail in the chapter <info:var>.
94
94
````
95
95
96
96
## A real-life analogy
97
97
98
98
We can easily grasp the concept of a "variable" if we imagine it as a "box" for data, with a uniquely-named sticker on it.
99
99
100
-
For instance, the variable `message` can be imagined as a box labeled `"message"` with the value `"Hello!"` in it:
100
+
For instance, the variable `message` can be imagined as a box labelled `"message"` with the value `"Hello!"` in it:
101
101
102
102

103
103
@@ -198,14 +198,14 @@ Variables named `apple` and `APPLE` are two different variables.
198
198
```
199
199
200
200
````smart header="Non-Latin letters are allowed, but not recommended"
201
-
It is possible to use any language, including cyrillic letters, Chinese logograms and so on, like this:
201
+
It is possible to use any language, including Cyrillic letters, Chinese logograms and so on, like this:
202
202
203
203
```js
204
204
let имя = '...';
205
205
let 我 = '...';
206
206
```
207
207
208
-
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time.
208
+
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it sometime.
myBirthday = '01.01.2001'; // error, can't reassign the constant!
261
261
```
262
262
263
-
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.
263
+
When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and communicate that fact to everyone.
264
264
265
265
### Uppercase constants
266
266
267
-
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
267
+
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known before execution.
268
268
269
269
Such constants are named using capital letters and underscores.
270
270
@@ -289,15 +289,15 @@ Benefits:
289
289
290
290
When should we use capitals for a constant and when should we name it normally? Let's make that clear.
291
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
+
Being a "constant" just means that a variable's value never changes. But some constants are known before execution (like a hexadecimal value for red) and some constants are *calculated* in run-time, during the execution, but do not change after their initial assignment.
293
293
294
294
For instance:
295
295
296
296
```js
297
297
const pageLoadTime = /* time taken by a webpage to load */;
298
298
```
299
299
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.
300
+
The value of `pageLoadTime` is not known before the page load, so it's named normally. But it's still a constant because it doesn't change after the assignment.
301
301
302
302
In other words, capital-named constants are only used as aliases for "hard-coded" values.
303
303
@@ -307,18 +307,18 @@ Talking about variables, there's one more extremely important thing.
307
307
308
308
A variable name should have a clean, obvious meaning, describing the data that it stores.
309
309
310
-
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer.
310
+
Variable naming is one of the most important and complex skills in programming. A glance at variable names can reveal which code was written by a beginner versus an experienced developer.
311
311
312
-
In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labeled. Or, in other words, when the variables have good names.
312
+
In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
313
313
314
314
Please spend time thinking about the right name for a variable before declaring it. Doing so will repay you handsomely.
315
315
316
316
Some good-to-follow rules are:
317
317
318
318
- Use human-readable names like `userName` or `shoppingCart`.
319
-
- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing.
319
+
- Stay away from abbreviations or short names like `a`, `b`, and `c`, unless you know what you're doing.
320
320
- Make names maximally descriptive and concise. Examples of bad names are `data` and `value`. Such names say nothing. It's only okay to use them if the context of the code makes it exceptionally obvious which data or value the variable is referencing.
321
-
- Agree on terms within your team and in your own mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`.
321
+
- Agree on terms within your team and in your mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`.
322
322
323
323
Sounds simple? Indeed it is, but creating descriptive and concise variable names in practice is not. Go for it.
As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter <info:bigint>. Read it when you need such big numbers.
96
96
97
-
98
-
```smart header="Compatibility issues"
99
-
Right now, `BigInt` is supported in Firefox/Chrome/Edge/Safari, but not in IE.
100
-
```
101
-
102
-
You can check [*MDN* BigInt compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) to know which versions of a browser are supported.
103
-
104
97
## String
105
98
106
99
A string in JavaScript must be surrounded by quotes.
Historically, the OR `||` operator was there first. It exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
79
+
Historically, the OR `||` operator was there first. It's been there since the beginning of JavaScript, so developers were using it for such purposes for a long time.
80
80
81
81
On the other hand, the nullish coalescing operator `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Teams behind JavaScript engines have their own ideas about what to implement fir
7
7
8
8
So it's quite common for an engine to implement only part of the standard.
9
9
10
-
A good page to see the current state of support for language features is <https://kangax.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
10
+
A good page to see the current state of support for language features is <https://compat-table.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
11
11
12
12
As programmers, we'd like to use most recent features. The more good stuff - the better!
13
13
@@ -73,7 +73,6 @@ JavaScript is a highly dynamic language. Scripts may add/modify any function, ev
73
73
74
74
Two interesting polyfill libraries are:
75
75
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
76
-
- [polyfill.io](https://polyfill.io/) service that provides a script with polyfills, depending on the features and user's browser.
77
76
78
77
79
78
## Summary
@@ -85,7 +84,7 @@ Just don't forget to use a transpiler (if using modern syntax or operators) and
85
84
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](https://webpack.js.org/) with the [babel-loader](https://github.com/babel/babel-loader) plugin.
86
85
87
86
Good resources that show the current state of support for various features:
88
-
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
87
+
- <https://compat-table.github.io/compat-table/es6/> - for pure JavaScript.
89
88
- <https://caniuse.com/> - for browser-related functions.
90
89
91
90
P.S. Google Chrome is usually the most up-to-date with language features, try it if a tutorial demo fails. Most tutorial demos work with any modern browser though.
0 commit comments