Conversion to boolean type in JavaScript

Let's now study the conversion of other data types to boolean. Such a transformation is carried out using the function Boolean. Here are the values that yield false when cast to boolean:

javascriptconsole.log(Boolean(0));          // false
console.log(Boolean(-0));         // false
console.log(Boolean(+0));         // false
console.log(Boolean(null));       // false
console.log(Boolean(false));      // false
console.log(Boolean(NaN));        // false
console.log(Boolean(undefined));  // false
console.log(Boolean(''));         // false

All other values in JavaScript (other languages don't) yield true. Here are the values that lead to true, but which may cause you doubts:

javascriptconsole.log(Boolean(-1));          // true
console.log(Boolean(Infinity));    // true
console.log(Boolean(-Infinity));   // true

The following values are strings because they are quoted and are also converted to true:

javascriptconsole.log(Boolean('0'));         // true
console.log(Boolean('false'));     // true
console.log(Boolean('NaN'));       // true
console.log(Boolean('null'));      // true
console.log(Boolean('undefined')); // true
Задание 1

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(3);
alert(test);
Задание 2

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(0);
alert(test);
Задание 3

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(-1);
alert(test);
Задание 4

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(-0);
alert(test);
Задание 5

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(+0);
alert(test);
Задание 6

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('abc');
alert(test);
Задание 7

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('');
alert(test);
Задание 8

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('0');
alert(test);
Задание 9

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(true);
alert(test);
Задание 10

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(false);
alert(test);
Задание 11

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('true');
alert(test);
Задание 12

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('false');
alert(test);
Задание 13

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(null);
alert(test);
Задание 14

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('null');
alert(test);
Задание 15

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(undefined);
alert(test);
Задание 16

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('undefined');
alert(test);
Задание 17

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(NaN);
alert(test);
Задание 18

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean('NaN');
alert(test);
Задание 19

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(3 * 'abc');
alert(test);
Задание 20

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(Infinity);
alert(test);
Задание 21

Without running the code, determine what will be displayed on the screen:

javascriptlet test = Boolean(1 / 0);
alert(test);