Skip to content

Sync with upstream @ 19223ae7 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
ef91e09
Fixed syntax error / typo
candh Apr 17, 2019
17223e6
Update index.md
JohnMcGuinness Apr 17, 2019
f776557
import typo
dragonwocky Apr 18, 2019
a63d623
vise -> vice
dragonwocky Apr 18, 2019
922170b
thee -> the
dragonwocky Apr 18, 2019
4f6864e
fix typo in article title
tadjik1 Apr 19, 2019
b6f0a67
Merge pull request #925 from tadjik1/patch-1
iliakan Apr 19, 2019
811491d
Update README.md
iliakan Apr 19, 2019
c62633c
Update README.md
iliakan Apr 19, 2019
b79ba7d
Update README.md
iliakan Apr 19, 2019
75c51cf
Update README.md
iliakan Apr 19, 2019
f3ea976
Update README.md
iliakan Apr 19, 2019
f6a7c12
Update README.md
iliakan Apr 19, 2019
becdb24
Update README.md
iliakan Apr 19, 2019
08fa870
Update README.md
iliakan Apr 19, 2019
df0c224
Update README.md
iliakan Apr 19, 2019
79f0463
Update README.md
iliakan Apr 19, 2019
557d170
Update solution.md
him2312 Apr 20, 2019
0697954
minor
iliakan Apr 20, 2019
65e805c
Minor grammar fix
mihansweatpants Apr 20, 2019
42ae87a
Fix typo
mihansweatpants Apr 20, 2019
f363b92
Fixed typo
alaabouayed Apr 20, 2019
3dbd493
Merge pull request #921 from candh/patch-1
iliakan Apr 21, 2019
de9f268
Merge pull request #922 from JohnMcGuinness/patch-1
iliakan Apr 21, 2019
333a00b
Merge pull request #924 from dragonwocky/patch-4
iliakan Apr 21, 2019
77581bc
Merge pull request #927 from him2312/patch-1
iliakan Apr 21, 2019
7b884bf
Merge pull request #928 from mihansweatpants/patch-1
iliakan Apr 21, 2019
0a2b817
Merge pull request #929 from mihansweatpants/patch-2
iliakan Apr 21, 2019
be9f48c
Merge pull request #930 from alaabouayed/patch-1
iliakan Apr 21, 2019
b8eb04d
classes: remove patterns
iliakan Apr 21, 2019
092f739
searching elements: make more modern
iliakan Apr 21, 2019
d67929c
Updated article.md (better sentence flow)
Apr 21, 2019
b38d426
minor
iliakan Apr 21, 2019
b91abf8
minor
iliakan Apr 21, 2019
74e6955
Merge pull request #932 from cmdlhz/cmdlhz-patch-1
iliakan Apr 21, 2019
7aa1e0f
Corrected grammar
alaabouayed Apr 21, 2019
14163bb
Grammar
alaabouayed Apr 21, 2019
3b3363e
Merge pull request #934 from alaabouayed/patch-2
iliakan Apr 22, 2019
585b77d
Merge pull request #933 from alaabouayed/patch-3
iliakan Apr 22, 2019
203b8f9
fixes
iliakan Apr 22, 2019
3b14ed8
minor
iliakan Apr 22, 2019
8ef9fd2
Clarity
alaabouayed Apr 22, 2019
c5ce557
Fix name of JavaScript
lex111 Apr 23, 2019
6f55ba6
Merge pull request #936 from lex111/js-correct
iliakan Apr 23, 2019
10f84e7
6-data-storage/01-cookie: fix typo
lex111 Apr 23, 2019
b9ca311
Merge pull request #935 from alaabouayed/patch-4
iliakan Apr 23, 2019
735880d
Replace `Node.JS` with `Node.js`
lex111 Apr 23, 2019
4c2ab73
Replace `Github` with `GitHub`
lex111 Apr 23, 2019
190f0de
Corrected grammar
Violet-Bora-Lee Apr 25, 2019
743a0dc
Fix typo
h-n-y Apr 25, 2019
340c147
Merge pull request #939 from Violet-Bora-Lee/patch-1
iliakan Apr 25, 2019
8735adc
Merge pull request #940 from h-n-y/h-n-y-patch-1
iliakan Apr 25, 2019
273e47b
cleanup
iliakan Apr 25, 2019
b7b073b
Update article.md
marksq Apr 25, 2019
b2f8974
up
iliakan Apr 25, 2019
3465665
minor
iliakan Apr 25, 2019
e30d9d4
minor
iliakan Apr 25, 2019
9f06601
minor
iliakan Apr 25, 2019
65c5793
#8: fix unordered list
Antiai Apr 25, 2019
a9ee52b
#8: fix unordered list (#942)
lex111 Apr 25, 2019
f74963a
js/first-steps/function-basics: fix name of Lodash
lex111 Apr 25, 2019
04487f8
Update article.md
david-cho-lerat-HL2 Apr 26, 2019
3b20808
Update article.md
david-cho-lerat-HL2 Apr 26, 2019
076a624
Merge pull request #941 from marksq/patch-1
iliakan Apr 26, 2019
f652b9d
Merge pull request #944 from david-cho-lerat-HL2/patch-2
iliakan Apr 26, 2019
298e894
Merge pull request #943 from david-cho-lerat-HL2/patch-1
iliakan Apr 26, 2019
19223ae
minor
iliakan Apr 26, 2019
fb10720
merging all conflicts
iliakan Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1-js/01-getting-started/1-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The engine applies optimizations at each step of the process. It even watches th

Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or CPU, because it was initially created for browsers which do not require it.

Javascript's capabilities greatly depend on the environment it's running in. For instance, [Node.JS](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc.
JavaScript's capabilities greatly depend on the environment it's running in. For instance, [Node.js](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc.

In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver.

Expand Down Expand Up @@ -88,7 +88,7 @@ There are at least *three* great things about JavaScript:
+ Simple things are done simply.
+ Support by all major browsers and enabled by default.
```
Javascript is the only browser technology that combines these three things.
JavaScript is the only browser technology that combines these three things.

That's what makes JavaScript unique. That's why it's the most widespread tool for creating browser interfaces.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/01-getting-started/3-devtools/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Now `key:Cmd+Opt+C` can toggle the console. Also, note that the new top menu ite

Usually, when we put a line of code into the console, and then press `key:Enter`, it executes.

To insert multiple line, press `key:Shift+Enter`.
To insert multiple lines, press `key:Shift+Enter`.

## Summary

Expand Down
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/01-hello-world/article.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Hello, world!

The tutorial that you're reading is about core JavaScript, which is platform-independent. Later on, you'll learn about Node.JS and other platforms that use it.
The tutorial that you're reading is about core JavaScript, which is platform-independent. Later on, you'll learn about Node.js and other platforms that use it.

But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.JS). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.

So first, let's see how we attach a script to a webpage. For server-side environments (like Node.JS), you can execute the script with a command like `"node my.js"`.
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`.


## The "script" tag
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/04-variables/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ let userName;
let test123;
```

When the name contains multiple words, [camelCase](https://en.wikipedia.org/wiki/CamelCase) is commonly used. That is: words go one after another, each word starting with a capital letter: `myVeryLongName`.
When the name contains multiple words, [camelCase](https://en.wikipedia.org/wiki/CamelCase) is commonly used. That is: words go one after another, each word except first starting with a capital letter: `myVeryLongName`.

What's interesting -- the dollar sign `'$'` and the underscore `'_'` can also be used in names. They are regular symbols, just like letters, without any special meaning.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/06-type-conversions/article.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Type Conversions

Most of the time, operators and functions automatically convert the values given to them to the right type. This is called "type conversion".
Most of the time, operators and functions automatically convert the values given to them to the right type.

For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/14-function-basics/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ These examples assume common meanings of prefixes. What they mean for you is det
```smart header="Ultrashort function names"
Functions that are used *very often* sometimes have ultrashort names.

For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [LoDash](http://lodash.com/) library has its core function named `_`.
For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [Lodash](http://lodash.com/) library has its core function named `_`.

These are exceptions. Generally functions names should be concise and descriptive.
```
Expand Down
2 changes: 1 addition & 1 deletion 1-js/03-code-quality/02-coding-style/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Most linters are integrated with many popular editors: just enable the plugin in

For instance, for ESLint you should do the following:

1. Install [Node.JS](https://nodejs.org/).
1. Install [Node.js](https://nodejs.org/).
2. Install ESLint with the command `npm install -g eslint` (npm is a JavaScript package installer).
3. Create a config file named `.eslintrc` in the root of your JavaScript project (in the folder that contains all your files).
4. Install/enable the plugin for your editor that integrates with ESLint. The majority of editors have one.
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/01-primitives-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The solution looks a little bit awkward, but here it is:

1. Primitives are still primitive. A single value, as desired.
2. The language allows access to methods and properties of strings, numbers, booleans and symbols.
3. When this happens, a special "object wrapper" is created that provides the extra functionality, and then is destroyed.
3. When this happens, a special "object wrapper" that provides the extra functionality is created, and then is destroyed.

The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean` and `Symbol`. Thus, they provide different sets of methods.

Expand Down
6 changes: 3 additions & 3 deletions 1-js/05-data-types/02-number/9-random-int-min-max/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Any number from the interval `min..max` must appear with the same probability.
Examples of its work:

```js
alert( random(1, 5) ); // 1
alert( random(1, 5) ); // 3
alert( random(1, 5) ); // 5
alert( randomInteger(1, 5) ); // 1
alert( randomInteger(1, 5) ); // 3
alert( randomInteger(1, 5) ); // 5
```

You can use the solution of the [previous task](info:task/random-min-max) as the base.
4 changes: 2 additions & 2 deletions 1-js/05-data-types/04-array/10-maximal-subarray/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ For instance, for `[-1, 2, 3, -9, 11]`:
-9
-9 + 11

// Starting from -11
-11
// Starting from 11
11
```

The code is actually a nested loop: the external loop over array elements, and the internal counts subsums starting with the current element.
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/10-date/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,4 @@ alert(`Loading started ${performance.now()}ms ago`);
// more than 3 digits after the decimal point are precision errors, but only the first 3 are correct
```

Node.JS has `microtime` module and other ways. Technically, any device and environment allows to get more precision, it's just not in `Date`.
Node.js has `microtime` module and other ways. Technically, any device and environment allows to get more precision, it's just not in `Date`.
4 changes: 2 additions & 2 deletions 1-js/06-advanced-functions/03-closure/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function sayHiBye(firstName, lastName) {
}
```

Here the *nested* function `getFullName()` is made for convenience. It can access the outer variables and so can return the full name. Nested functions are quite common in Javascript.
Here the *nested* function `getFullName()` is made for convenience. It can access the outer variables and so can return the full name. Nested functions are quite common in JavaScript.

What's much more interesting, a nested function can be returned: either as a property of a new object (if the outer function creates an object with methods) or as a result by itself. It can then be used somewhere else. No matter where, it still has access to the same outer variables.

Expand Down Expand Up @@ -473,7 +473,7 @@ The code outside of the block (or inside another script) doesn't see variables i

### IIFE

In the past, there were no block-level lexical environment in Javascript.
In the past, there were no block-level lexical environment in JavaScript.

So programmers had to invent something. And what they did is called "immediately-invoked function expressions" (abbreviated as IIFE).

Expand Down
4 changes: 2 additions & 2 deletions 1-js/06-advanced-functions/05-global-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

The global object provides variables and functions that are available anywhere. Mostly, the ones that are built into the language or the host environment.

In a browser it is named "window", for Node.JS it is "global", for other environments it may have another name.
In a browser it is named "window", for Node.js it is "global", for other environments it may have another name.

For instance, we can call `alert` as a method of `window`:

Expand Down Expand Up @@ -79,7 +79,7 @@ No, it's not, because it may lead to naming conflicts: the same variable name ca

As of now, the multi-purpose `window` is considered a design mistake in the language.

Luckily, there's a "road out of hell", called "Javascript modules".
Luckily, there's a "road out of hell", called "JavaScript modules".

If we set `type="module"` attribute on a `<script>` tag, then such script is considered a separate "module" with its own top-level scope (lexical environment), not interfering with `window`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are two methods for it:
- `setTimeout` allows to run a function once after the interval of time.
- `setInterval` allows to run a function regularly with the interval between the runs.

These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.JS.
These methods are not a part of JavaScript specification. But most environments have the internal scheduler and provide these methods. In particular, they are supported in all browsers and Node.js.


## setTimeout
Expand Down Expand Up @@ -99,7 +99,7 @@ clearTimeout(timerId);
alert(timerId); // same identifier (doesn't become null after canceling)
```

As we can see from `alert` output, in a browser the timer identifier is a number. In other environments, this can be something else. For instance, Node.JS returns a timer object with additional methods.
As we can see from `alert` output, in a browser the timer identifier is a number. In other environments, this can be something else. For instance, Node.js returns a timer object with additional methods.

Again, there is no universal specification for these methods, so that's fine.

Expand Down Expand Up @@ -382,7 +382,7 @@ First timers run immediately (just as written in the spec), and then the delay c

That limitation comes from ancient times and many scripts rely on it, so it exists for historical reasons.

For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html) for Node.JS. So the notion is browser-specific only.
For server-side JavaScript, that limitation does not exist, and there exist other ways to schedule an immediate asynchronous job, like [process.nextTick](https://nodejs.org/api/process.html) and [setImmediate](https://nodejs.org/api/timers.html) for Node.js. So the notion is browser-specific only.
````

### Allowing the browser to render
Expand Down
2 changes: 1 addition & 1 deletion 1-js/06-advanced-functions/10-bind/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let f = user.sayHi;
setTimeout(f, 1000); // lost user context
```

The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.JS, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases as we'll see, usually `this` just becomes `undefined`.
The method `setTimeout` in-browser is a little special: it sets `this=window` for the function call (for Node.js, `this` becomes the timer object, but doesn't really matter here). So for `this.firstName` it tries to get `window.firstName`, which does not exist. In other similar cases as we'll see, usually `this` just becomes `undefined`.

The task is quite typical -- we want to pass an object method somewhere else (here -- to the scheduler) where it will be called. How to make sure that it will be called in the right context?

Expand Down
7 changes: 3 additions & 4 deletions 1-js/07-object-properties/01-property-descriptors/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,13 @@ Property descriptors work at the level of individual properties.
There are also methods that limit access to the *whole* object:

[Object.preventExtensions(obj)](mdn:js/Object/preventExtensions)
: Forbids to add properties to the object.
: Forbids the addition of new properties to the object.

[Object.seal(obj)](mdn:js/Object/seal)
: Forbids to add/remove properties, sets for all existing properties `configurable: false`.
: Forbids adding/removing of properties. Sets `configurable: false` for all existing properties.

[Object.freeze(obj)](mdn:js/Object/freeze)
: Forbids to add/remove/change properties, sets for all existing properties `configurable: false, writable: false`.

: Forbids adding/removing/changing of properties. Sets `configurable: false, writable: false` for all existing properties.
And also there are tests for them:

[Object.isExtensible(obj)](mdn:js/Object/isExtensible)
Expand Down
2 changes: 1 addition & 1 deletion 1-js/08-prototypes/02-function-prototype/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ On the picture, `"prototype"` is a horizontal arrow, meaning a regular property,
```smart header="`F.prototype` only used at `new F` time"
`F.prototype` property is only used when `new F` is called, it assigns `[[Prototype]]` of the new object. After that, there's no connection between `F.prototype` and the new object. Think of it as a "one-time gift".

If, after the creation, `F.prototype` property changes (`F.property = <another object>`), then new objects created by `new F` will have another object as `[[Prototype]]`, but already existing objects keep the old one.
If, after the creation, `F.prototype` property changes (`F.prototype = <another object>`), then new objects created by `new F` will have another object as `[[Prototype]]`, but already existing objects keep the old one.
```

## Default F.prototype, constructor property
Expand Down
6 changes: 3 additions & 3 deletions 1-js/08-prototypes/04-prototype-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

In the first chapter of this section, we mentioned that there are modern methods to setup a prototype.

The `__proto__` is considered outdated and somewhat deprecated (in browser-only part of the Javascript standard).
The `__proto__` is considered outdated and somewhat deprecated (in browser-only part of the JavaScript standard).

The modern methods are:

Expand Down Expand Up @@ -76,12 +76,12 @@ That's for historical reasons.

As of now we have all these ways at our disposal.

Why `__proto__` was replaced by the functions? That's an interesting question, requiring us to understand why `__proto__` is bad. Read on to get the answer.
Why was `__proto__` replaced by the functions? That's an interesting question, requiring us to understand why `__proto__` is bad. Read on to get the answer.

```warn header="Don't reset `[[Prototype]]` unless the speed doesn't matter"
Technically, we can get/set `[[Prototype]]` at any time. But usually we only set it once at the object creation time, and then do not modify: `rabbit` inherits from `animal`, and that is not going to change.

And JavaScript engines are highly optimized to that. Changing a prototype "on-the-fly" with `Object.setPrototypeOf` or `obj.__proto__=` is a very slow operation, it breaks internal optimizations for object property access operations. So evade it unless you know what you're doing, or Javascript speed totally doesn't matter for you.
And JavaScript engines are highly optimized to that. Changing a prototype "on-the-fly" with `Object.setPrototypeOf` or `obj.__proto__=` is a very slow operation, it breaks internal optimizations for object property access operations. So evade it unless you know what you're doing, or JavaScript speed totally doesn't matter for you.
```

## "Very plain" objects
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading