Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
parmentelat committed May 10, 2017
1 parent f16b0cf commit 936a921
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The test demonstrates one of temptations a developer meets when writing tests.
The test demonstrates one of the temptations a developer meets when writing tests.

What we have here is actually 3 tests, but layed out as a single function with 3 asserts.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/03-code-quality/05-testing-mocha/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ The spec can be used in three ways:
2. **Docs** -- the titles of `describe` and `it` tell what the function does.
3. **Examples** -- the tests are actually working examples showing how a function can be used.
With the spec, we can safely improve, change, even rewrite the function from the scratch and make sure it still works right.
With the spec, we can safely improve, change, even rewrite the function from scratch and make sure it still works right.
That's especially important in large projects when a function is used in many places. When we change such a function -- there's just no way to manually check if every place that uses them still works right.
Expand Down
2 changes: 1 addition & 1 deletion 1-js/03-code-quality/06-polyfills/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Here Babel.JS comes to the rescue.

Actually, there are two parts in Babel:

1. First, the transpiler program, which rewrites the code. The developer run it on his own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
1. First, the transpiler program, which rewrites the code. The developer runs it on his own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.

2. Second, the polyfill.

Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/01-object/2-hello-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ importance: 5

# Hello, object

Write the code, each line for an action:
Write the code, one line for each action:

1. Create an empty object `user`.
2. Add the property `name` with the value `John`.
Expand Down
12 changes: 6 additions & 6 deletions 1-js/04-object-basics/01-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let user = { // an object
};
```

A property has a key (also known as "name" and "identifier") before the colon `":"` and a value to the right of it.
A property has a key (also known as "name" or "identifier") before the colon `":"` and a value to the right of it.

In the `user` object, there are two properties:

Expand Down Expand Up @@ -125,7 +125,7 @@ delete user["likes birds"];

Now everything is fine. Please note that the string inside the brackets is properly quoted (any type of quotes will do).

Square brackets are also provide a way to access a property by the name from the variable:
Square brackets also provide a way to obtain the property name as the result of any expression - as opposed to a litteral string - like from a variable as follows:

```js
let key = "likes birds";
Expand All @@ -134,7 +134,7 @@ let key = "likes birds";
user[key] = true;
```

Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility. The dot notation cannot be used in similar way.
Here, the variable `key` may be calculated at run-time or depend on the user input. And then we use it to access the property. That gives us a great deal of flexibility. The dot notation cannot be used in a similar way.

For instance:

Expand Down Expand Up @@ -270,7 +270,7 @@ let user = {
};
```

## Existance check
## Existence check

A notable objects feature is that it's possible to access any property. There will be no error if the property doesn't exist! Accessing a non-existing property just returns `undefined`. It provides a very common way to test whether the property exists -- to get it and compare vs undefined:

Expand All @@ -296,7 +296,7 @@ alert( "age" in user ); // true, user.age exists
alert( "blabla" in user ); // false, user.blabla doesn't exist
```

Please note that at the left side of `in` there must be a *property name*. That's usually a quoted string.
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.

If we omit quotes, that would mean a variable containing the actual name to be tested. For instance:

Expand Down Expand Up @@ -698,7 +698,7 @@ alert(clone.sizes.width); // 51, see the result from the other one
To fix that, we should use the cloning loop that examines each value of `user[key]` and, if it's an object, then replicate it's structure as well. That is called a "deep cloning".
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](https://w3c.github.io/html/infrastructure.html#internal-structured-cloning-algorithm). Not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](https://w3c.github.io/html/infrastructure.html#internal-structured-cloning-algorithm). In order not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
Expand Down
4 changes: 2 additions & 2 deletions 1-js/04-object-basics/02-garbage-collection/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ delete family.mother.husband;

![](family-delete-refs.png)

It's not enough to delete any one of them, because all objects would still be reachable.
It's not enough to delete only one of these two references, because all objects would still be reachable.

But if we delete both, then we can see that John has no incoming references any more:
But if we delete both, then we can see that John has no incoming reference any more:

![](family-no-father.png)

Expand Down
2 changes: 1 addition & 1 deletion 1-js/04-object-basics/03-symbol/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ For instance, different parts of our application want to access symbol `"id"` me

To achieve that, there exists a *global symbol registry*. We can create symbols in it and and access them later, and it guarantees that repeated accesses by the same name return exactly the same symbol.

To can create or read a symbol in the registry, use `Symbol.for(name)`.
In order to create or read a symbol in the registry, use `Symbol.for(name)`.

For instance:

Expand Down
10 changes: 5 additions & 5 deletions 1-js/04-object-basics/04-object-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ In non-strict mode (if one forgets `use strict`) the value of `this` in such cas
Please note that usually a call of a function that uses `this` without an object is not normal, but rather a programming mistake. If a function has `this`, then it is usually meant to be called in the context of an object.

```smart header="The consequences of unbound `this`"
If you come from another programming languages, then you are probably used to an idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.
If you come from another programming language, then you are probably used to the idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.

In JavaScript `this` is "free", its value is evaluated at the call time and depends not on where the method was declared, but rather on what's the object "before dot".
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what's the object "before the dot".

The concept of run-time evaluated `this` has both pluses and minuses. From one side, a function can be reused for different objects. From the other side, greater flexibility opens a place for mistakes.
The concept of run-time evaluated `this` has both pluses and minuses. On the one hand, a function can be reused for different objects. On the the other hand, greater flexibility opens a place for mistakes.

Here our position is not to judge whether this language design decision is good or bad. We'll understand how to work with it, how to get benefits and evade problems.
```
Expand All @@ -238,7 +238,7 @@ This section covers an advanced topic, to understand certain edge-cases better.
If you want to go on faster, it can be skipped or postponed.
```

An intricate method call can loose `this`, for instance:
An intricate method call can lose `this`, for instance:

```js run
let user = {
Expand Down Expand Up @@ -322,7 +322,7 @@ So, as the result, the value of `this` is only passed the right way if the funct

## Arrow functions have no "this"

Arrow functions are special: they don't have "own" `this`. If we reference `this` from such function, it's taken from the outer "normal" function.
Arrow functions are special: they don't have their "own" `this`. If we reference `this` from such a function, it's taken from the outer "normal" function.

For instance, here `arrow()` uses `this` from the outer `user.sayHi()` method:

Expand Down
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/06-constructor-new/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The constructor can't be called again, because it is not saved anywhere, just cr

## Dual-use constructors: new.target

Inside a function, we can check how it is called with `new` or without it, using a special `new.target` property.
Inside a function, we can check whether it was called with `new` or without it, using a special `new.target` property.

It is empty for ordinary runs and equals the function if called with `new`:

Expand Down Expand Up @@ -116,7 +116,7 @@ let john = User("John"); // redirects call to new User
alert(john.name); // John
```

This approach is sometimes used in libraries to make the syntax more flexible. Probably not a good thing to use everywhere though, because it makes a bit less obvious what's going on for a person who's familiar with internals of `User`.
This approach is sometimes used in libraries to make the syntax more flexible. Probably not a good thing to use everywhere though, because it makes a bit less obvious what's going on for a person who's familiar with the internals of `User`.

## Return from constructors

Expand Down Expand Up @@ -158,7 +158,7 @@ function SmallUser() {
alert( new SmallUser().name ); // John
```

Most of time constructors return nothing. Here we mention the special behavior with returning objects mainly for the sake of completeness.
Most of the time constructors return nothing. Here we mention the special behavior with returning objects mainly for the sake of completeness.

````smart header="Omitting brackets"
By the way, we can omit brackets after `new`, if it has no arguments:
Expand Down Expand Up @@ -208,7 +208,7 @@ john = {
- Constructor functions or, shortly, constructors, are regular functions, but there's a common agreement to name them with capital letter first.
- Constructor functions should only be called using `new`. Such call implies a creation of empty `this` at the start and returning the populated one at the end.

We can use constructor functions to make multiple similar objects. But the topic is much deeper than described here. So we'll return it later and cover more in-depth.
We can use constructor functions to make multiple similar objects. But the topic is much deeper than described here. So we'll return to it later and cover it more in-depth.

JavaScript provides constructor functions for many built-in language objects: like `Date` for dates, `Set` for sets and others that we plan to study.

Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/01-primitives-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ An object
: Is capable of storing multiple values as properties.
Can be created with `{}`, for instance: `{name: "John", age: 30}`. There are other kinds of objects in JavaScript, e.g. functions are objects.

One of the best thing about objects is that we can store a function as one of properties:
One of the best things about objects is that we can store a function as one of properties:

```js run
let john = {
Expand Down Expand Up @@ -85,7 +85,7 @@ We'll see more specific methods in chapters <info:number> and <info:string>.
````warn header="Constructors `String/Number/Boolean` are for internal use only"
Some languages like Java allow to create "wrapper objects" for primitives explicitly using syntax like `new Number(1)` or `new Boolean(false)`.

In JavaScript that's also possible for historical reasons, but highly not recommended. Things will go crazy in many places.
In JavaScript that's also possible for historical reasons, but highly **not recommended**. Things will go crazy in many places.

For instance:

Expand All @@ -95,7 +95,7 @@ alert( typeof 1 ); // "number"
alert( typeof new Number(1) ); // "object"!
```

And, because `zero` is an object:
And, because in what follows `zero` is an object, the alert will show up:

```js run
let zero = new Number(0);
Expand All @@ -105,7 +105,7 @@ if (zero) { // zero is true, because it's an object
}
```

From the other side, using same functions `String/Number/Boolean` without `new` is a totally sane and useful thing. They convert a value to the corresponding type: to a string, a number, or a boolean (primitive).
From the other side, using the same functions `String/Number/Boolean` without `new` is a totally sane and useful thing. They convert a value to the corresponding type: to a string, a number, or a boolean (primitive).

This is totally valid:
```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Here the precision loss made the number a little bit greater, so it rounded up.

**How can we fix the problem with `6.35` if we want it to be rounded the right way?**

We should use bring it closer to an integer prior to rounding:
We should bring it closer to an integer prior to rounding:

```js run
alert( (6.35 * 10).toFixed(20) ); // 63.50000000000000000000
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/02-number/2-why-rounded-down/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For instance:
alert( 1.35.toFixed(1) ); // 1.4
```

How do you think why in the similar example below `6.35` is rounded to `6.3`, not `6.4`?
In the similar example below, why is `6.35` rounded to `6.3`, not `6.4`?

```js run
alert( 6.35.toFixed(1) ); // 6.3
Expand Down
4 changes: 2 additions & 2 deletions 1-js/05-data-types/02-number/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Imagine, we need to write a billion. The obvious way is:
let billion = 1000000000;
```

But in real life we usually dislike writing many zeroes. It's easy to mistype. Also we are lazy. We we usually write something like `"1bn"` for a billion or `"7.3bn"` for 7 billions 300 millions. The similar is true for other big numbers.
But in real life we usually dislike writing many zeroes. It's easy to mistype. Also we are lazy. We will usually write something like `"1bn"` for a billion or `"7.3bn"` for 7 billions 300 millions. The similar is true for other big numbers.

In JavaScript, we can do almost the same by appending the letter `"e"` to the number and specifying the zeroes count:

Expand Down Expand Up @@ -44,7 +44,7 @@ let ms = 1e-6; // six zeroes to the left from 1

If we count the zeroes in `0.000001`, there are 6 of them. So naturally it's `1e-6`.

In other words, a negative number after `"e"` means a division by 1 with the given number of zeries:
In other words, a negative number after `"e"` means a division by 1 with the given number of zeroes:

```js
// -3 divides by 1 with 3 zeroes
Expand Down
8 changes: 4 additions & 4 deletions 1-js/05-data-types/03-string/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ There are multiple ways to look for a substring in a string.

The first method is [str.indexOf(substr, pos)](mdn:js/String/indexOf).

It looks for the `substr` in `str`, starting from the given position `pos`, and returns the position where the match was found or `-1` if nothing found.
It looks for the `substr` in `str`, starting from the given position `pos`, and returns the position where the match was found or `-1` if nothing can be found.

For instance:

Expand Down Expand Up @@ -337,7 +337,7 @@ if (~str.indexOf("Widget")) {
}
```
It is usually not recommended to use language features in a non-obvious way, but this particular trick is widely used in the old code, so we should understand it.
It is usually not recommended to use language features in a non-obvious way, but this particular trick is widely used in old code, so we should understand it.
Just remember: `if (~str.indexOf(...))` reads as "if found".
````
Expand Down Expand Up @@ -476,7 +476,7 @@ Although, there are some oddities.

That may lead to strange results if we sort country names. Usually people would await for `Zealand` to be after `Österreich` in the list.

To understand what happens, let's review the internal representaion of strings in JavaScript.
To understand what happens, let's review the internal representation of strings in JavaScript.
All strings are encoded using [UTF-16](https://en.wikipedia.org/wiki/UTF-16). That is: each character has a corresponding numeric code. There are special methods that allow to get the character for the code and back.
Expand All @@ -496,7 +496,7 @@ All strings are encoded using [UTF-16](https://en.wikipedia.org/wiki/UTF-16). Th
alert( String.fromCodePoint(90) ); // Z
```
We can also add unicode charactes by their codes using `\u` followed by the hex code:
We can also add unicode characters by their codes using `\u` followed by the hex code:
```js run
// 90 is 5a in hexadecimal system
Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/04-array/1-item-value/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ importance: 3

# Is array copied?

What this code is going to show?
What is this code going to show?

```js
let fruits = ["Apples", "Pear", "Orange"];
Expand Down
10 changes: 5 additions & 5 deletions 1-js/05-data-types/04-array/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fruits[2] = 'Pear'; // now ["Apple", "Orange", "Pear"]
...Or add a new one to the array:

```js
fruits[3] = 'Lemon'; // now ["Apple", "Orange", "Plum", "Lemon"]
fruits[3] = 'Lemon'; // now ["Apple", "Orange", "Pear", "Lemon"]
```

The total count of the elements in the array is its `length`:
Expand Down Expand Up @@ -211,7 +211,7 @@ arr.push("Pear"); // modify the array by reference
alert( fruits ); // Banana, Pear - 2 items now
```

...But what makes arrays really special is their internal representation. The engine tries to store its elements in the contiguous memory area, one after another, just as painted on the illustrations in this chapter, and there are other optimizations as well, to make arrays work really fast.
...But what makes arrays really special is their internal representation. The engine tries to store its elements in the contiguous memory area, one after another, just as depicted on the illustrations in this chapter, and there are other optimizations as well, to make arrays work really fast.

But they all break if we quit working with an array as with an "ordered collection" and start working with it as if it were a regular object.

Expand All @@ -225,7 +225,7 @@ fruits[99999] = 5; // assign a property with the index far greater than its leng
fruits.age = 25; // create a property with an arbitrary name
```

That's possible, because arrays are objects at base. We can add any properties to them.
That's possible, because arrays are objects at their base. We can add any properties to them.

But the engine will see that we're working with the array as with a regular object. Array-specific optimizations are not suited for such cases and will be turned off, their benefits disappear.

Expand All @@ -235,7 +235,7 @@ The ways to misuse an array:
- Make holes, like: add `arr[0]` and then `arr[1000]` (and nothing between them).
- Fill the array in the reverse order, like `arr[1000]`, `arr[999]` and so on.

Please think of arrays as about special structures to work with the *ordered data*. They provide special methods for that. Arrays are carefully tuned inside JavaScript engines to work with contiguous ordered data, please use them this way. And if you need arbitrary keys, chances are high that you actually require a regular object `{}`.
Please think of arrays as special structures to work with the *ordered data*. They provide special methods for that. Arrays are carefully tuned inside JavaScript engines to work with contiguous ordered data, please use them this way. And if you need arbitrary keys, chances are high that you actually require a regular object `{}`.

## Performance

Expand Down Expand Up @@ -344,7 +344,7 @@ Note that we usually don't use arrays like that.

Another interesting thing about the `length` property is that it's writable.

If we increase it manually, nothing interesting happens. But if we decrease it, the array is truncated. The process is irreversable, here's the example:
If we increase it manually, nothing interesting happens. But if we decrease it, the array is truncated. The process is irreversible, here's the example:

```js run
let arr = [1, 2, 3, 4, 5];
Expand Down
Loading

0 comments on commit 936a921

Please sign in to comment.