minor fixes
This commit is contained in:
parent
2289134483
commit
b782700818
5 changed files with 7 additions and 7 deletions
|
@ -121,7 +121,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
|
|||
|
||||
Another feature of OR `||` operator is the so-called "short-circuit" evaluation.
|
||||
|
||||
It means that `||` processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument.
|
||||
It means that `||` processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument.
|
||||
|
||||
That importance of this feature becomes obvious if an operand isn't just a value, but an expression with a side effect, such as a variable assignment or a function call.
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ alert( *!*key*/!* in user ); // true, property "age" exists
|
|||
|
||||
Why does the `in` operator exist? Isn't it enough to compare against `undefined`?
|
||||
|
||||
Well, most of the time the comparison with `undefined` works fine. But there's But there's a special case when it fails, but `"in"` works correctly.
|
||||
Well, most of the time the comparison with `undefined` works fine. But there's a special case when it fails, but `"in"` works correctly.
|
||||
|
||||
It's when an object property exists, but stores `undefined`:
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ arr.push(function() {
|
|||
alert( this );
|
||||
})
|
||||
|
||||
arr[2](); // "a","b",function
|
||||
arr[2](); // a,b,function(){...}
|
||||
```
|
||||
|
||||
The array has 3 values: initially it had two, plus the function.
|
||||
|
|
|
@ -156,7 +156,7 @@ In computer science the data structure that allows this, is called [deque](https
|
|||
`shift`
|
||||
: Extracts the first element of the array and returns it:
|
||||
|
||||
```js
|
||||
```js run
|
||||
let fruits = ["Apple", "Orange", "Pear"];
|
||||
|
||||
alert( fruits.shift() ); // remove Apple and alert it
|
||||
|
@ -167,7 +167,7 @@ In computer science the data structure that allows this, is called [deque](https
|
|||
`unshift`
|
||||
: Add the element to the beginning of the array:
|
||||
|
||||
```js
|
||||
```js run
|
||||
let fruits = ["Orange", "Pear"];
|
||||
|
||||
fruits.unshift('Apple');
|
||||
|
|
|
@ -225,11 +225,11 @@ But there's a subtle difference between `Array.from(obj)` and `[...obj]`:
|
|||
So, for the task of turning something into an array, `Array.from` tends to be more universal.
|
||||
|
||||
|
||||
## Get a new copy of an object/array
|
||||
## Get a new copy of an array/object
|
||||
|
||||
Remember when we talked about `Object.assign()` [in the past](https://javascript.info/object#cloning-and-merging-object-assign)?
|
||||
|
||||
It is possible to do the same thing with the spread operator!
|
||||
It is possible to do the same thing with the spread syntax.
|
||||
|
||||
```js run
|
||||
let arr = [1, 2, 3];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue