Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Coerce to Boolean

Fundamentals: Part 1easy

Course · Section 2: JavaScript Fundamentals – Part 1 · Lecture 11: Data Types

Implement `toBool(value)` returning the boolean truthiness of `value`.

Sample tests

Input: toBool(0)
Output: false
Input: toBool("hi")
Output: true

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Strings like '0' or 'false' are truthy, since any non-empty string is truthy.

Learning resources

  • MDN: typeof
Visualize this concept: Data Types and Coercion →
Approach & explanation (try first)

Boolean() collapses a value to its truthiness following the standard falsy list.

Loading...
⌘/Ctrl + Enter

Run your code to see results.