logicial operators Flashcards

1
Q

alert( true || true ); //
alert( false || true ); //
alert( true || false ); //
alert( false || false ); //

A

// true
// true
// true
// false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

let firstName = “”;
let lastName = “”;
let nickName = “SuperCoder”;

alert( firstName || lastName || nickName || “Anonymous”); // returns

A

SuperCoder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

true || alert(“not printed”);
false || alert(“printed”);

what runs and why?

A

printed

In the first line, the OR || operator stops the evaluation immediately upon seeing true, so the alert isn’t run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

alert( true && true ); //
alert( false && true ); //
alert( true && false ); //
alert( false && false ); //

A

alert( true && true ); // true
alert( false && true ); // false
alert( true && false ); // false
alert( false && false ); // false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The AND && operator does the following: Evaluates operands from _____

If all operands have been evaluated (i.e. all were truthy), returns the ______

A

left to right.

last operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

alert( 1 && 0 ); // returns and why

A

0

last true value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

alert( null && 5 ); // returns and why?

A

null

// if the first operand is falsy,
// AND returns it. The second operand is ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

alert( 0 && “no matter what” ); // returns and why?

A

0

// if the first operand is falsy,
// AND returns it. The second operand is ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

alert( 1 && 2 && null && 3 ); //

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

alert( 1 && 2 && 3 ); // returns

A

3
the last one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

alert( !true );

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

alert( !0 ); //

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A double _____ is sometimes used for converting a value to boolean type:

A

A double NOT !!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

alert( !!”non-empty string” ); // returns

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

alert( null || 2 || undefined );
// returns and why

A

2
The answer is 2, that’s the first truthy value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

alert( alert(1) || 2 || alert(3) );

A

alert 1
2

The second operand 2 is truthy, so the execution is halted, 2 is returned and then shown by the outer alert.

17
Q

alert( 1 && null && 2 );
returns and why?

A

The answer: null, because it’s the first falsy value from the list.

18
Q

If all operands have been evaluated (i.e. all were false), returns the last operand.

A

||

19
Q

The difference is that ____ returns the first falsy value

&& or || operator?

A

&&

20
Q

_______ returns the first truthy one.

A

||