logicial operators Flashcards
alert( true || true ); //
alert( false || true ); //
alert( true || false ); //
alert( false || false ); //
// true
// true
// true
// false
let firstName = “”;
let lastName = “”;
let nickName = “SuperCoder”;
alert( firstName || lastName || nickName || “Anonymous”); // returns
SuperCoder
true || alert(“not printed”);
false || alert(“printed”);
what runs and why?
printed
In the first line, the OR || operator stops the evaluation immediately upon seeing true, so the alert isn’t run.
alert( true && true ); //
alert( false && true ); //
alert( true && false ); //
alert( false && false ); //
alert( true && true ); // true
alert( false && true ); // false
alert( true && false ); // false
alert( false && false ); // false
The AND && operator does the following: Evaluates operands from _____
If all operands have been evaluated (i.e. all were truthy), returns the ______
left to right.
last operand.
alert( 1 && 0 ); // returns and why
0
last true value
alert( null && 5 ); // returns and why?
null
// if the first operand is falsy,
// AND returns it. The second operand is ignored
alert( 0 && “no matter what” ); // returns and why?
0
// if the first operand is falsy,
// AND returns it. The second operand is ignored
alert( 1 && 2 && null && 3 ); //
null
alert( 1 && 2 && 3 ); // returns
3
the last one
alert( !true );
false
alert( !0 ); //
true
A double _____ is sometimes used for converting a value to boolean type:
A double NOT !!
alert( !!”non-empty string” ); // returns
true
alert( null || 2 || undefined );
// returns and why
2
The answer is 2, that’s the first truthy value.