JavaScript Boolean Logic & Truthy/Falsy Quiz

JavaScript
0 Passed
0% acceptance

Explore 50 JavaScript questions covering boolean values, logical operators, comparison pitfalls, truthy/falsy coercion, short-circuit flow, optional chaining, nullish coalescing, ternaries, and real-world conditional patterns.

50 Questions
~100 minutes
1

Question 1

What are the only boolean literal values in JavaScript?

A
true and false
B
1 and 0
C
yes and no
D
truth and falsity
2

Question 2

What does the typeof operator return for a boolean literal?

javascript
console.log(typeof true)
A
boolean
B
object
C
true
D
undefined
3

Question 3

Which built-in function converts any value into an explicit boolean?

A
Boolean()
B
parseBool()
C
toBoolean()
D
Number()
4

Question 4

What does the Boolean constructor return when called without new on an empty string?

javascript
console.log(Boolean(''))
A
false
B
true
C
null
D
undefined
5

Question 5

Which statement accurately describes primitive booleans vs Boolean objects?

A
Primitive booleans are lightweight values; Boolean objects are wrappers with type object.
B
They are identical in every way.
C
Boolean objects are faster.
D
Primitive booleans cannot be compared.
6

Question 6

What does the logical AND (&&) operator return?

A
The first falsy operand or the last value if all are truthy
B
Always true or false
C
A number representing truthiness
D
Only the boolean literal true
7

Question 7

Given the code, what logs to the console?

javascript
console.log('A' && 0 && 'B')
A
0
B
A
C
B
D
true
8

Question 8

What does the logical OR (||) operator return?

A
The first truthy operand or the last value if all are falsy
B
Only boolean true
C
Always either true or false
D
An object describing the operands
9

Question 9

What prints for the following OR expression?

javascript
console.log(null || 'fallback' || 42)
A
'fallback'
B
null
C
42
D
undefined
10

Question 10

What is the outcome of applying the logical NOT (!) to a truthy value?

A
It becomes false
B
It stays truthy
C
It throws an error
D
It becomes undefined
11

Question 11

Which comparison operator checks value and type equality without coercion?

A
===
B
==
C
=
D
<=>
12

Question 12

What does this comparison output?

javascript
console.log(0 == false)
A
true
B
false
C
undefined
D
Throws TypeError
13

Question 13

What does the strict equality comparison log?

javascript
console.log('0' === 0)
A
false
B
true
C
Throws TypeError
D
undefined
14

Question 14

Which expression evaluates to true?

A
'5' == 5
B
'5' === 5
C
'5' === '5' && 5 === '5'
D
5 == true
15

Question 15

How does JavaScript compare booleans to numbers with > or < operators?

A
Booleans coerce to 1 for true and 0 for false before comparison
B
Comparison throws
C
Booleans stay booleans
D
Booleans turn into strings
16

Question 16

Which list contains only falsy values in JavaScript?

A
false, 0, "", null, undefined, NaN
B
false, [], {}, ""
C
0, "0", null
D
false, true, 0
17

Question 17

What is the boolean value of an empty array?

javascript
console.log(Boolean([]))
A
true
B
false
C
undefined
D
Throws TypeError
18

Question 18

Which value is truthy?

A
'0'
B
0
C
NaN
D
''
19

Question 19

What does the following log?

javascript
const value = ' ';
console.log(Boolean(value))
A
true
B
false
C
null
D
undefined
20

Question 20

Which value remains falsy even after JSON parsing?

A
null
B
"false"
C
"0"
D
"[]"
21

Question 21

What is short-circuit evaluation?

A
Stopping evaluation as soon as the final outcome is determined
B
Evaluating every operand regardless of result
C
Converting numbers to booleans
D
Optimising arithmetic operators only
22

Question 22

What prints in this short-circuit example?

javascript
let calls = 0;
const left = () => (++calls, false);
const right = () => (++calls, true);
left() && right();
console.log(calls)
A
1
B
2
C
0
D
Throws ReferenceError
23

Question 23

How can logical AND be used for conditional execution?

A
condition && doSomething() executes doSomething only when condition is truthy
B
It always executes both sides
C
It throws if condition is falsy
D
It converts functions to booleans
24

Question 24

What does the OR operator commonly replace in defaulting logic?

A
value || fallback returns fallback when value is falsy
B
value || fallback always returns fallback
C
It throws if fallback is missing
D
It converts fallback to boolean
25

Question 25

What is a drawback of using || for defaults?

A
Falsy but valid values like 0 or "" get replaced unintentionally
B
It runs slower than if statements
C
It only works inside loops
D
It requires strict mode
26

Question 26

What does the double NOT (!!) operator do?

A
Converts a value to its boolean equivalent
B
Squares a value
C
Throws on falsy values
D
Returns the original value unchanged
27

Question 27

What logs to the console?

javascript
const input = 'hello';
console.log(!!input)
A
true
B
false
C
'hello'
D
undefined
28

Question 28

Which option shows coercion of a number into a boolean without using !! or Boolean()?

A
Using double negation via bitwise NOT twice: !!value
B
Using value ? true : false
C
Calling value.toBoolean()
D
Prefixing with +value
29

Question 29

What is the boolean result of applying !! to NaN?

A
false
B
true
C
NaN
D
Throws TypeError
30

Question 30

When using the Boolean wrapper with new, what type does the result have?

A
object
B
boolean
C
function
D
symbol
31

Question 31

What value logs from this conditional?

javascript
const flag = '';
if (flag) {
  console.log('truthy');
} else {
  console.log('falsy');
}
A
falsy
B
truthy
C
true
D
undefined
32

Question 32

What does the ternary operator return?

A
condition ? valueIfTrue : valueIfFalse returns either branch based on the condition
B
It always returns true
C
It only works with booleans
D
It modifies the condition variable
33

Question 33

What prints from this ternary expression?

javascript
const score = 0;
const label = score ? 'Positive' : 'Zero or Negative';
console.log(label)
A
'Zero or Negative'
B
'Positive'
C
0
D
true
34

Question 34

How can you guard against executing a function when a reference might be undefined?

A
maybeFn && maybeFn()
B
maybeFn() regardless
C
Using = instead of ==
D
Wrapping in Number()
35

Question 35

What is a common readability improvement over nested ternaries?

A
Using if/else blocks when logic branches more than twice
B
Using more parentheses
C
Inlining everything on one line
D
Switching to bitwise operators
36

Question 36

What does Array.prototype.some return?

A
true if at least one element passes the test
B
true only if all elements pass
C
The element that passed
D
The index of the last element
37

Question 37

What prints here?

javascript
const fruits = [];
if (fruits) {
  console.log('has array');
}
A
'has array'
B
Nothing
C
false
D
Throws TypeError
38

Question 38

How can you check if an object has any own enumerable properties before acting?

A
if (Object.keys(obj).length) { ... }
B
if (obj) { ... } always works
C
obj ?? {}
D
Using obj === true
39

Question 39

What boolean value does Array.prototype.includes return?

A
true or false depending on whether the item exists
B
The index of the element
C
A filtered array
D
undefined when not found
40

Question 40

Why might you wrap optional property access in Boolean()?

A
To convert undefined or null into false when checking presence
B
To stringify objects
C
To avoid garbage collection
D
To memoise the property
41

Question 41

What does optional chaining (?.) prevent?

A
Accessing properties on null/undefined values from throwing
B
All runtime errors
C
Network requests
D
Type coercion
42

Question 42

What logs here?

javascript
const config = null;
console.log(config?.mode)
A
undefined
B
Throws TypeError
C
null
D
mode
43

Question 43

How does nullish coalescing (??) differ from logical OR?

A
?? only falls back when the left operand is null or undefined
B
?? also treats 0 as needing fallback
C
?? converts booleans to strings
D
?? requires strict mode
44

Question 44

What is printed?

javascript
const qty = 0;
console.log(qty ?? 10)
A
0
B
10
C
undefined
D
null
45

Question 45

Which expression safely calls an optional method only if it exists?

A
obj?.handler?.()
B
obj.handler() always
C
obj ?? handler()
D
obj.handler?.call() without arguments
46

Question 46

Why can comparing arrays with === be misleading in boolean checks?

A
=== checks reference equality, so two distinct arrays are never equal even if contents match
B
Arrays automatically coerce to numbers
C
Arrays throw when compared
D
Arrays are falsy
47

Question 47

What is a pitfall when checking for NaN using equality?

A
NaN is not equal to itself, so comparisons fail
B
NaN equals 0
C
NaN always coerces to true
D
NaN becomes undefined
48

Question 48

How can double negation lead to bugs when used in return statements?

A
It may hide the actual value by converting it to true/false, losing information
B
It slows down execution significantly
C
It only works in strict mode
D
It prevents garbage collection
49

Question 49

Why can mixing || and ?? without parentheses cause syntax errors?

A
JavaScript forbids mixing them due to ambiguous precedence unless grouped
B
They are identical operators
C
They require TypeScript
D
It only happens in strict mode
50

Question 50

What is a safe strategy when writing complex boolean expressions?

A
Break them into well-named helper variables or functions for clarity
B
Compress everything into one line
C
Avoid using parentheses
D
Rely on operator precedence charts instead of clarity

QUIZZES IN JavaScript