Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Address some possible issues in 1.2.11#2134

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iliakan merged 1 commit intojavascript-tutorial:masterfromvsemozhetbyt:1.2.11
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,6 @@ importance: 3

# Check the range between

Write an"if" condition to check that `age` is between `14` and `90` inclusively.
Write an`if` condition to check that `age` is between `14` and `90` inclusively.

"Inclusively" means that `age` can reach the edges `14` or `90`.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,6 @@ importance: 3

# Check the range outside

Write an `if` condition to check that `age` is NOT between14 and90 inclusively.
Write an `if` condition to check that `age` is NOT between`14` and`90` inclusively.

Create two variants: the first one using NOT `!`, the second one -- without it.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,19 +3,19 @@
```js run demo
let userName = prompt("Who's there?", '');

if (userName == 'Admin') {
if (userName === 'Admin') {

let pass = prompt('Password?', '');

if (pass == 'TheMaster') {
if (pass === 'TheMaster') {
alert( 'Welcome!' );
} else if (pass == '' || pass == null) {
} else if (pass === '' || pass=== null) {
alert( 'Canceled' );
} else {
alert( 'Wrong password' );
}

} else if (userName == '' || userName == null) {
} else if (userName === '' || userName=== null) {
alert( 'Canceled' );
} else {
alert( "I don't know you" );
Expand Down
12 changes: 6 additions & 6 deletions1-js/02-first-steps/11-logical-operators/article.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 truthy 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:

Expand All@@ -101,9 +101,9 @@ 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.**

For instance, we have `firstName`, `lastName` and `nickName` variables, all optional.
For instance, we have `firstName`, `lastName` and `nickName` variables, all optional (i.e. can be undefined or have falsy values).

Let's use OR `||` to choose the one that has the data and show it (or `anonymous` if nothing set):
Let's use OR `||` to choose the one that has the data and show it (or `"Anonymous"` if nothing set):

```js run
let firstName = "";
Expand All@@ -115,7 +115,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
*/!*
```

If all variables were falsy, `Anonymous` would show up.
If all variables were falsy, `"Anonymous"` would show up.

2. **Short-circuit evaluation.**

Expand DownExpand Up@@ -223,7 +223,7 @@ The precedence of AND `&&` operator is higher than OR `||`.
So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`.
````

````warn header="Don't replace `if` with|| or&&"
````warn header="Don't replace `if` with`||` or`&&`"
Sometimes, people use the AND `&&` operator as a "shorter way to write `if`".

For instance:
Expand All@@ -244,7 +244,7 @@ let x = 1;
if (x > 0) alert( 'Greater than zero!' );
```

Although, the variant with `&&` appears shorter, `if` is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use `if` if we wantif and use `&&` if we want AND.
Although, the variant with `&&` appears shorter, `if` is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use `if` if we want`if` and use `&&` if we want AND.
````


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp