fixes
This commit is contained in:
parent
3623a881f3
commit
db4d0de26d
3 changed files with 9 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
# Interaction: alert, prompt, confirm
|
||||
|
||||
This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks.
|
||||
In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks.
|
||||
|
||||
But we'll still be using the browser as our demo environment, so we should know at least a few of its user-interface functions. In this chapter, we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Sometimes, we need to perform different actions based on different conditions.
|
||||
|
||||
To do that, we use the `if` statement and the conditional (ternary) operator which we will be referring to as the “question mark” operator `?` for simplicity.
|
||||
To do that, we can use the `if` statement and the conditional operator `?`, that's also called a "question mark" operator.
|
||||
|
||||
## The "if" statement
|
||||
|
||||
|
@ -103,7 +103,7 @@ In the code above, JavaScript first checks `year < 2015`. If that is falsy, it g
|
|||
|
||||
There can be more `else if` blocks. The final `else` is optional.
|
||||
|
||||
## Ternary operator '?'
|
||||
## Conditional operator '?'
|
||||
|
||||
Sometimes, we need to assign a variable depending on a condition.
|
||||
|
||||
|
@ -124,9 +124,9 @@ if (age > 18) {
|
|||
alert(accessAllowed);
|
||||
```
|
||||
|
||||
The so-called "ternary" or "question mark" operator lets us do that in a shorter and simpler way.
|
||||
The so-called "conditional" or "question mark" operator lets us do that in a shorter and simpler way.
|
||||
|
||||
The operator is represented by a question mark `?`. The formal term "ternary" means that the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
|
||||
The operator is represented by a question mark `?`. Sometimes it's called "ternary", because the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
|
||||
|
||||
The syntax is:
|
||||
```js
|
||||
|
|
|
@ -84,7 +84,7 @@ The OR `||` operator does the following:
|
|||
|
||||
A value is returned in its original form, without the conversion.
|
||||
|
||||
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found.
|
||||
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found.
|
||||
|
||||
For instance:
|
||||
|
||||
|
@ -101,7 +101,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
|
|||
|
||||
1. **Getting the first truthy value from a list of variables or expressions.**
|
||||
|
||||
Imagine we have several variables which can either contain data or be `null/undefined`. How can we find the first one with data?
|
||||
Imagine we have a list of variables which can either contain data or be `null/undefined`. How can we find the first one with data?
|
||||
|
||||
We can use OR `||`:
|
||||
|
||||
|
@ -143,7 +143,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
|
|||
alert(x); // 1
|
||||
```
|
||||
|
||||
An assignment is a simple case. Other side effects can also be involved.
|
||||
An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them.
|
||||
|
||||
As we can see, such a use case is a "shorter way of doing `if`". The first operand is converted to boolean. If it's false, the second one is evaluated.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue