Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
iliakan committed Aug 3, 2017
2 parents ab40409 + dd88ae4 commit 1bb1293
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/08-comparison/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ The same thing with an empty string:
alert( '' == false ); // true
```

That's because operands of different types are converted to a number by the assignment operator `=`. An empty string, just like `false`, becomes a zero.
That's because operands of different types are converted to a number by the equality operator `==`. An empty string, just like `false`, becomes a zero.

What to do if we'd like to differentiate `0` from `false`?

Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/09-alert-prompt-confirm/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ We covered 3 browser-specific functions to interact with the visitor:
: shows a message.
`prompt`
: shows a message asking the user to input text. It returns the text or, if CANCEL or `key:Esc` is clicked, all browsers except Safari return `null`.
: shows a message asking the user to input text. It returns the text or, if CANCEL or `key:Esc` is clicked, all browsers return `null`.
`confirm`
: shows a message and waits for the user to press "OK" or "CANCEL". It returns `true` for OK and `false` for CANCEL/`key:Esc`.
Expand Down
22 changes: 11 additions & 11 deletions 1-js/02-first-steps/10-ifelse/article.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Conditional operators: if, '?'

Sometimes we need to perform different actions basing on a condition.
Sometimes we need to perform different actions based on a condition.

There's an `if` operator for that and also the "question mark" operator: `"?"` for conditional evaluation.
There is `if` statement for that and also the conditional (ternary) operator for conditional evaluation which we will be referring as “question mark operator: `"?"` for simplicity.

[cut]

## The "if" operator
## The "if" statement

The "if" operator gets a condition, evaluates it and -- if the result is `true` -- executes the code.
The "if" statement gets a condition, evaluates it and -- if the result is `true` -- executes the code.

For example:

Expand All @@ -22,7 +22,7 @@ if (year == 2015) alert( 'You are right!' );

In the example above, the condition is a simple equality check: `year == 2015`, but it can be much more complex.

If there's more than one command to execute -- we can use a code block in figure brackets:
If there is more than one command to execute -- we can use a code block in figure brackets:

```js
if (year == 2015) {
Expand All @@ -31,11 +31,11 @@ if (year == 2015) {
}
```

It is recommended to use figure brackets every time with `if`, even if there's only one command. That improves readability.
It is recommended to use figure brackets every time with `if`, even if there is only one command. That improves readability.

## Boolean conversion

The `if (…)` operator evaluates the expression in parentheses and converts it to the boolean type.
The `if (…)` statement evaluates the expression in parentheses and converts it to the boolean type.

Let's recall the conversion rules from the chapter <info:type-conversions>:

Expand Down Expand Up @@ -70,7 +70,7 @@ if (cond) {

## The "else" clause

The `if` operator may contain an optional "else" block. It executes when the condition is wrong.
The `if` statement may contain an optional "else" block. It executes when the condition is wrong.

For example:
```js run
Expand All @@ -85,7 +85,7 @@ if (year == 2015) {

## Several conditions: "else if"

Sometimes we'd like to test several variants of a condition. There's an `else if` clause for that.
Sometimes we'd like to test several variants of a condition. There is an `else if` clause for that.

For example:

Expand Down Expand Up @@ -220,7 +220,7 @@ We don't assign a result to a variable here, the idea is to execute different co

The notation seem to be shorter than `if`, that appeals to some programmers. But it is less readable.

Here's the same with `if` for comparison:
Here is the same with `if` for comparison:

```js run no-beautify
let company = prompt('Which company created JavaScript?', '');
Expand All @@ -236,4 +236,4 @@ if (company == 'Netscape') {

Our eyes scan the code vertically. The constructs which span several lines are easier to understand than a long horizontal instruction set.

The idea of a question mark `'?'` is to return one or another value depending on the condition. Please use it for exactly that. There's `if` to execute different branches of the code.
The idea of a question mark `'?'` is to return one or another value depending on the condition. Please use it for exactly that. There is `if` to execute different branches of the code.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Right now they are fully independent.

But we'd want `Rabbit` to extend `Animal`. In other words, rabbits should be based on animals, have access to methods of `Animal` and extend them with its own methods.

What does it mean in the language on prototypes?
What does it mean in the language of prototypes?

Right now methods for `rabbit` objects are in `Rabbit.prototype`. We'd like `rabbit` to use `Animal.prototype` as a "fallback", if the method is not found in `Rabbit.prototype`.

Expand Down

0 comments on commit 1bb1293

Please sign in to comment.