JavaScript Type Conversion & Coercion Quiz
Explore 50 JavaScript questions that test implicit coercion, explicit casts, string and number conversions, truthy/falsy evaluations, equality quirks, arithmetic side effects, ToPrimitive algorithms, JSON behavior, and the most common pitfalls developers hit when the engine reshapes data types.
Question 1
Which built-in function converts any value to a string explicitly?
Question 2
What does typeof return for the result of Number("42")?
Question 3
Which statement describes implicit type coercion?
Question 4
Which ECMAScript abstract operation governs how objects turn into primitives during coercion?
Question 5
When does JavaScript invoke valueOf on an object?
Question 6
What is the result of "5" - 1?
Question 7
How does JavaScript evaluate [] + {}?
Question 8
What does {} + [] evaluate to in most runtimes?
Question 9
What is the output of the following code?
console.log(null + 5)Question 10
Which expression demonstrates implicit string coercion?
Question 11
Which API converts a value to an integer by truncating fractional parts toward zero?
Question 12
What does Number.parseFloat("12.34px") return?
Question 13
How can you convert a boolean to a string without calling String()?
Question 14
What is the safest way to convert a string to an integer in base 10?
Question 15
Which method converts numbers to strings with a specified number of decimal places?
Question 16
What does String(undefined) return?
Question 17
How does template literal interpolation handle objects with custom toString?
const obj = { toString: () => 'custom' }
console.log(`Value: ${obj}`)Question 18
Which expression coerces a number to a string by concatenation?
Question 19
Why can toString on numbers throw an error?
Question 20
What string results from ({}).toString()?
Question 21
What does Number(true) evaluate to?
Question 22
What is the result of +"-0"?
Question 23
Which value becomes NaN when passed to Number()?
Question 24
What does parseInt("0x10", 16) return?
Question 25
Which operator can quickly truncate a floating number to 32-bit signed integer?
Question 26
Which list contains only falsy values during boolean conversion?
Question 27
What does Boolean("0") return?
Question 28
What is the boolean value of !!null?
Question 29
Which expression leverages short-circuit evaluation to assign a default only when value is falsy?
Question 30
Why might you prefer ?? over || for defaults?
Question 31
What does "5" + 3 evaluate to?
Question 32
What is the result of [] == false?
Question 33
Which equality operator skips type coercion?
Question 34
What does "0" == false evaluate to?
Question 35
Which comparison causes numeric coercion on both operands?
Question 36
What does true * 2 evaluate to?
Question 37
Which expression results in NaN due to coercion rules?
Question 38
How does JavaScript evaluate "5" > "12"?
Question 39
What does [] == ![] evaluate to?
Question 40
Which comparison returns false?
Question 41
What does JSON.stringify({ valueOf() { return 2 } }) return?
Question 42
How can you customize ToPrimitive for an object?
Question 43
What does the following code log?
const obj = {
valueOf() {
return 5
},
toString() {
return 'seven'
}
}
console.log(`${obj}`)Question 44
What is the result of +new Date("2020-01-01")?
Question 45
Which method is used by JSON.stringify when an object defines toJSON?
Question 46
Why can using +obj where obj is an object be risky?
Question 47
What is a common bug when using parseInt on array.map results?
Question 48
Why should equality comparisons avoid mixing == with objects and primitives?
Question 49
What happens when adding a number to undefined?
Question 50
What is a safer strategy when dealing with user input that could be numeric or string data?
