Course: JavaScript

Progress (0%)

  1. Foundation

  2. Numbers

  3. Strings

  4. Conditions

  5. Loops

  6. Arrays

  7. Functions

  8. Objects

  9. Exceptions

  10. HTML DOM

  11. CSSOM

  12. Events

  13. Drag and Drop

  14. opt Touch Events

  15. Misc

  16. Project: Analog Clock

JavaScript Booleans Quiz

Quiz 8 10 questions

Prerequisites for the quiz

  1. JavaScript Conditions — Booleans

Are you ready?

10 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Given an arbitrary value val, both Boolean(val) and !!val return back the same value. True or false?
Indeed, both Boolean() and !! return back the exact same value when called on any value in JavaScript. Hence, the correct choice is (A). For more info, refer to JavaScript Conditions — Booleans: Converting to Boolean.
Given an arbitrary value val, both Boolean(val) and new Boolean(val) return back the same value. True or false?
False; Boolean() returns back a Boolean primitive while new Boolean() returns back a Boolean object, which clearly aren't the same in any way. For more info, refer to JavaScript Conditions — Booleans: The Boolean() constructor.
When converted to a Boolean, '' becomes ...
'' becomes false, and this goes with choice (B). For more info, refer to JavaScript Conditions — Booleans: Boolean conversion rules.
When converted to a Boolean, an empty array ([]) becomes ...
An empty array ([]) in JavaScript coerces to the Boolean true since every single object value coerces to true. For more info, refer to JavaScript Conditions — Booleans: Boolean conversion rules.
All numbers in JavaScript except for only 0 get converted to true. True or false?
False; another number value NaN also gets converted to false; it's not just 0. For more info, refer to JavaScript Conditions — Booleans: Boolean conversion rules.
An object with no property gets converted to the Boolean ...
An object, no matter what its kind or number of properties, converts to true. As simple as that. Hence the correct choice is (A). For more info, refer to JavaScript Conditions — Booleans: Boolean conversion rules.
What does the following code log?
console.log(true === Boolean(undefined));
Boolean(undefined) returns false, so the comparison expression becomes true === false which obviously yields false. For more info, refer to JavaScript Conditions — Booleans.
What does the following code log?
console.log(undefined === Boolean(undefined));
Boolean(undefined) returns false, so the comparison expression becomes undefined === false which then yields false, because undefined is not identical to false. For more info, refer to JavaScript Conditions — Booleans.
In JavaScript, the Boolean literal true can also be expressed ...
The literals true and false are keywords in JavaScript and are, therefore, case-sensitive. So, they can only be expressed as true and false. Hence, the correct choice is (D). For more info, refer to JavaScript Conditions — Booleans: Creating Booleans.
Which of the following values evaluates to a Boolean primitive?
true and false are the straightforward right choices, so we get (A) and (F). Besides these, the comparison expression in (D) and the double negation (!!) also return Boolean primitives. And that's it. For more info, refer to JavaScript Conditions — Booleans.