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/03-code-quality/01-debugging-chrome/article.md
+10-11
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ If we press `key:Esc`, then a console opens below. We can type commands there an
38
38
39
39
After a statement is executed, its result is shown below.
40
40
41
-
For example, here `1+2` results in `3`, and`hello("debugger")` returns nothing, so the result is `undefined`:
41
+
For example, here `1+2` results in `3`, while the function call`hello("debugger")` returns nothing, so the result is `undefined`:
42
42
43
43

44
44
@@ -63,12 +63,12 @@ We can always find a list of breakpoints in the right panel. That's useful when
63
63
- ...And so on.
64
64
65
65
```smart header="Conditional breakpoints"
66
-
*Right click* on the line number allows to create a *conditional* breakpoint. It only triggers when the given expression is truthy.
66
+
*Right click* on the line number allows to create a *conditional* breakpoint. It only triggers when the given expression, that you should provide when you create it, is truthy.
67
67
68
68
That's handy when we need to stop only for a certain variable value or for certain function parameters.
69
69
```
70
70
71
-
## Debugger command
71
+
## The command "debugger"
72
72
73
73
We can also pause the code by using the `debugger` command in it, like this:
74
74
@@ -84,8 +84,7 @@ function hello(name) {
84
84
}
85
85
```
86
86
87
-
That's very convenient when we are in a code editor and don't want to switch to the browser and look up the script in developer tools to set the breakpoint.
88
-
87
+
Such command works only when the development tools are open, otherwise the browser ignores it.
89
88
90
89
## Pause and look around
91
90
@@ -99,7 +98,7 @@ Please open the informational dropdowns to the right (labeled with arrows). They
99
98
100
99
1.**`Watch` -- shows current values for any expressions.**
101
100
102
-
You can click the plus `+` and input an expression. The debugger will show its value at any moment, automatically recalculating it in the process of execution.
101
+
You can click the plus `+` and input an expression. The debugger will show its value, automatically recalculating it in the process of execution.
103
102
104
103
2.**`Call Stack` -- shows the nested calls chain.**
105
104
@@ -135,11 +134,11 @@ There are buttons for it at the top of the right panel. Let's engage them.
135
134
Clicking this again and again will step through all script statements one by one.
136
135
137
136
<spanclass="devtools"style="background-position:-62px-192px"></span> -- "Step over": run the next command, but *don't go into a function*, hotkey `key:F10`.
138
-
: Similar to the previous "Step" command, but behaves differently if the next statement is a function call. That is: not a built-in, like `alert`, but a function of our own.
137
+
: Similar to the previous "Step" command, but behaves differently if the next statement is a function call (not a built-in, like `alert`, but a function of our own).
139
138
140
-
The "Step" command goes into it and pauses the execution at its first line, while "Step over" executes the nested function call invisibly, skipping the function internals.
139
+
If we compare them, the "Step" command goes into a nested function call and pauses the execution at its first line, while "Step over" executes the nested function call invisibly to us, skipping the function internals.
141
140
142
-
The execution is then paused immediately after that function.
141
+
The execution is then paused immediately after that function call.
143
142
144
143
That's good if we're not interested to see what happens inside the function call.
145
144
@@ -155,7 +154,7 @@ There are buttons for it at the top of the right panel. Let's engage them.
155
154
: That button does not move the execution. Just a mass on/off for breakpoints.
156
155
157
156
<spanclass="devtools"style="background-position:-90px-146px"></span> -- enable/disable automatic pause in case of an error.
158
-
: When enabled, and the developer tools is open, a script error automatically pauses the execution. Then we can analyze variables to see what went wrong. So if our script dies with an error, we can open debugger, enable this option and reload the page to see where it dies and what's the context at that moment.
157
+
: When enabled, if the developer tools is open, an error during the script execution automatically pauses it. Then we can analyze variables in the debugger to see what went wrong. So if our script dies with an error, we can open debugger, enable this option and reload the page to see where it dies and what's the context at that moment.
159
158
160
159
```smart header="Continue to here"
161
160
Right click on a line of code opens the context menu with a great option called "Continue to here".
@@ -187,7 +186,7 @@ As we can see, there are three main ways to pause a script:
187
186
2. The `debugger` statements.
188
187
3. An error (if dev tools are open and the button <spanclass="devtools"style="background-position:-90px-146px"></span> is "on").
189
188
190
-
When paused, we can debug - examine variables and trace the code to see where the execution goes wrong.
189
+
When paused, we can debug: examine variables and trace the code to see where the execution goes wrong.
191
190
192
191
There are many more options in developer tools than covered here. The full manual is at <https://developers.google.com/web/tools/chrome-devtools>.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/05-testing-mocha/article.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ describe("pow", function() {
51
51
A spec has three main building blocks that you can see above:
52
52
53
53
`describe("title", function() { ... })`
54
-
: What functionality we're describing. In our case we're describing the function `pow`. Used to group "workers" -- the `it` blocks.
54
+
: What functionality we're describing? In our case we're describing the function `pow`. Used to group "workers" -- the `it` blocks.
55
55
56
56
`it("use case description", function() { ... })`
57
57
: In the title of `it` we *in a human-readable way* describe the particular use case, and the second argument is a function that tests it.
@@ -69,7 +69,7 @@ The flow of development usually looks like this:
69
69
70
70
1. An initial spec is written, with tests for the most basic functionality.
71
71
2. An initial implementation is created.
72
-
3. To check whether it works, we run the testing framework [Mocha](http://mochajs.org/) (more details soon) that runs the spec. While the functionality is not complete, errors are displayed. We make corrections until everything works.
72
+
3. To check whether it works, we run the testing framework [Mocha](https://mochajs.org/) (more details soon) that runs the spec. While the functionality is not complete, errors are displayed. We make corrections until everything works.
73
73
4. Now we have a working initial implementation with tests.
74
74
5. We add more use cases to the spec, probably not yet supported by the implementations. Tests start to fail.
75
75
6. Go to 3, update the implementation till tests give no errors.
@@ -79,15 +79,15 @@ So, the development is *iterative*. We write the spec, implement it, make sure t
79
79
80
80
Let's see this development flow in our practical case.
81
81
82
-
The first step is already complete: we have an initial spec for `pow`. Now, before making the implementation, let's use few JavaScript libraries to run the tests, just to see that they are working (they will all fail).
82
+
The first step is already complete: we have an initial spec for `pow`. Now, before making the implementation, let's use a few JavaScript libraries to run the tests, just to see that they are working (they will all fail).
83
83
84
84
## The spec in action
85
85
86
86
Here in the tutorial we'll be using the following JavaScript libraries for tests:
87
87
88
-
-[Mocha](http://mochajs.org/) -- the core framework: it provides common testing functions including `describe` and `it` and the main function that runs tests.
89
-
-[Chai](http://chaijs.com) -- the library with many assertions. It allows to use a lot of different assertions, for now we need only `assert.equal`.
90
-
-[Sinon](http://sinonjs.org/) -- a library to spy over functions, emulate built-in functions and more, we'll need it much later.
88
+
-[Mocha](https://mochajs.org/) -- the core framework: it provides common testing functions including `describe` and `it` and the main function that runs tests.
89
+
-[Chai](https://www.chaijs.com/) -- the library with many assertions. It allows to use a lot of different assertions, for now we need only `assert.equal`.
90
+
-[Sinon](https://sinonjs.org/) -- a library to spy over functions, emulate built-in functions and more, we'll need it much later.
91
91
92
92
These libraries are suitable for both in-browser and server-side testing. Here we'll consider the browser variant.
93
93
@@ -338,14 +338,14 @@ The newly added tests fail, because our implementation does not support them. Th
338
338
```smart header="Other assertions"
339
339
Please note the assertion `assert.isNaN`: it checks for `NaN`.
340
340
341
-
There are other assertions in [Chai](http://chaijs.com) as well, for instance:
341
+
There are other assertions in [Chai](https://www.chaijs.com/) as well, for instance:
342
342
343
343
- `assert.equal(value1, value2)` -- checks the equality `value1 == value2`.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
2
2
# Polyfills and transpilers
3
3
4
-
The JavaScript language steadily evolves. New proposals to the language appear regularly, they are analyzed and, if considered worthy, are appended to the list at <https://tc39.github.io/ecma262/> and then progress to the [specification](http://www.ecma-international.org/publications/standards/Ecma-262.htm).
4
+
The JavaScript language steadily evolves. New proposals to the language appear regularly, they are analyzed and, if considered worthy, are appended to the list at <https://tc39.github.io/ecma262/> and then progress to the [specification](https://www.ecma-international.org/publications-and-standards/standards/ecma-262/).
5
5
6
6
Teams behind JavaScript engines have their own ideas about what to implement first. They may decide to implement proposals that are in draft and postpone things that are already in the spec, because they are less interesting or just harder to do.
7
7
8
-
So it's quite common for an engine to implement only the part of the standard.
8
+
So it's quite common for an engine to implement only part of the standard.
9
9
10
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).
11
11
@@ -40,9 +40,9 @@ Now the rewritten code is suitable for older JavaScript engines.
40
40
41
41
Usually, a developer runs the transpiler on their own computer, and then deploys the transpiled code to the server.
42
42
43
-
Speaking of names, [Babel](https://babeljs.io) is one of the most prominent transpilers out there.
43
+
Speaking of names, [Babel](https://babeljs.io) is one of the most prominent transpilers out there.
44
44
45
-
Modern project build systems, such as [webpack](http://webpack.github.io/), provide means to run transpiler automatically on every code change, so it's very easy to integrate into development process.
45
+
Modern project build systems, such as [webpack](https://webpack.js.org/), provide a means to run a transpiler automatically on every code change, so it's very easy to integrate into the development process.
46
46
47
47
## Polyfills
48
48
@@ -69,20 +69,20 @@ if (!Math.trunc) { // if no such function
69
69
}
70
70
```
71
71
72
-
JavaScript is a highly dynamic language, scripts may add/modify any functions, even including built-in ones.
72
+
JavaScript is a highly dynamic language. Scripts may add/modify any function, even built-in ones.
73
73
74
-
Two interesting libraries of polyfills are:
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](http://polyfill.io) service that provides a script with polyfills, depending on the features and user's browser.
76
+
- [polyfill.io](https://polyfill.io/) service that provides a script with polyfills, depending on the features and user's browser.
77
77
78
78
79
79
## Summary
80
80
81
81
In this chapter we'd like to motivate you to study modern and even "bleeding-edge" language features, even if they aren't yet well-supported by JavaScript engines.
82
82
83
-
Just don't forget to use transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). And they'll ensure that the code works.
83
+
Just don't forget to use a transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). They'll ensure that the code works.
84
84
85
-
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](http://webpack.github.io/) with [babel-loader](https://github.com/babel/babel-loader) plugin.
85
+
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
86
87
87
Good resources that show the current state of support for various features:
88
88
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
0 commit comments