Skip to content

Commit f9397e3

Browse files
Merge pull request #162
main sync
2 parents 86086c8 + db41377 commit f9397e3

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

1-js/03-code-quality/01-debugging-chrome/article.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If we press `key:Esc`, then a console opens below. We can type commands there an
3838

3939
After a statement is executed, its result is shown below.
4040

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`:
4242

4343
![](chrome-sources-console.svg)
4444

@@ -63,12 +63,12 @@ We can always find a list of breakpoints in the right panel. That's useful when
6363
- ...And so on.
6464

6565
```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.
6767
6868
That's handy when we need to stop only for a certain variable value or for certain function parameters.
6969
```
7070

71-
## Debugger command
71+
## The command "debugger"
7272

7373
We can also pause the code by using the `debugger` command in it, like this:
7474

@@ -84,8 +84,7 @@ function hello(name) {
8484
}
8585
```
8686

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.
8988

9089
## Pause and look around
9190

@@ -99,7 +98,7 @@ Please open the informational dropdowns to the right (labeled with arrows). They
9998

10099
1. **`Watch` -- shows current values for any expressions.**
101100

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.
103102

104103
2. **`Call Stack` -- shows the nested calls chain.**
105104

@@ -135,11 +134,11 @@ There are buttons for it at the top of the right panel. Let's engage them.
135134
Clicking this again and again will step through all script statements one by one.
136135

137136
<span class="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).
139138

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.
141140

142-
The execution is then paused immediately after that function.
141+
The execution is then paused immediately after that function call.
143142

144143
That's good if we're not interested to see what happens inside the function call.
145144

@@ -155,7 +154,7 @@ There are buttons for it at the top of the right panel. Let's engage them.
155154
: That button does not move the execution. Just a mass on/off for breakpoints.
156155

157156
<span class="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.
159158

160159
```smart header="Continue to here"
161160
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:
187186
2. The `debugger` statements.
188187
3. An error (if dev tools are open and the button <span class="devtools" style="background-position:-90px -146px"></span> is "on").
189188

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.
191190

192191
There are many more options in developer tools than covered here. The full manual is at <https://developers.google.com/web/tools/chrome-devtools>.
193192

1-js/03-code-quality/05-testing-mocha/article.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("pow", function() {
5151
A spec has three main building blocks that you can see above:
5252

5353
`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.
5555

5656
`it("use case description", function() { ... })`
5757
: 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:
6969

7070
1. An initial spec is written, with tests for the most basic functionality.
7171
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.
7373
4. Now we have a working initial implementation with tests.
7474
5. We add more use cases to the spec, probably not yet supported by the implementations. Tests start to fail.
7575
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
7979

8080
Let's see this development flow in our practical case.
8181

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).
8383

8484
## The spec in action
8585

8686
Here in the tutorial we'll be using the following JavaScript libraries for tests:
8787

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.
9191

9292
These libraries are suitable for both in-browser and server-side testing. Here we'll consider the browser variant.
9393

@@ -338,14 +338,14 @@ The newly added tests fail, because our implementation does not support them. Th
338338
```smart header="Other assertions"
339339
Please note the assertion `assert.isNaN`: it checks for `NaN`.
340340
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:
342342
343343
- `assert.equal(value1, value2)` -- checks the equality `value1 == value2`.
344344
- `assert.strictEqual(value1, value2)` -- checks the strict equality `value1 === value2`.
345345
- `assert.notEqual`, `assert.notStrictEqual` -- inverse checks to the ones above.
346346
- `assert.isTrue(value)` -- checks that `value === true`
347347
- `assert.isFalse(value)` -- checks that `value === false`
348-
- ...the full list is in the [docs](http://chaijs.com/api/assert/)
348+
- ...the full list is in the [docs](https://www.chaijs.com/api/assert/)
349349
```
350350
351351
So we should add a couple of lines to `pow`:

1-js/03-code-quality/06-polyfills/article.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
# Polyfills and transpilers
33

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/).
55

66
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.
77

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.
99

1010
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).
1111

@@ -40,9 +40,9 @@ Now the rewritten code is suitable for older JavaScript engines.
4040
4141
Usually, a developer runs the transpiler on their own computer, and then deploys the transpiled code to the server.
4242
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.
4444
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.
4646
4747
## Polyfills
4848
@@ -69,20 +69,20 @@ if (!Math.trunc) { // if no such function
6969
}
7070
```
7171
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.
7373
74-
Two interesting libraries of polyfills are:
74+
Two interesting polyfill libraries are:
7575
- [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.
7777
7878
7979
## Summary
8080
8181
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.
8282
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.
8484
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.
8686
8787
Good resources that show the current state of support for various features:
8888
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.

0 commit comments

Comments
 (0)