Type conversion - to boolean
converting primitive types to boolean
WHEN converting undefined THEN it converts to false
WHEN converting null THEN it converts to false
WHEN converting 0 THEN it converts to false, its falsey
WHEN converting 23 THEN it converts to true, its truthy, as any number different to 0, -0 and +0
WHEN converting NaN THEN it converts to false, its falsey
WHEN converting an empty string THEN it converts to false, its falsey
WHEN converting any NOT-empty string THEN it converts to true, its truthy
converting non-primitives (like Object, Array, Function, ...)
WHEN converting an empty object THEN this converts to true (just like a object with properties too)
WHEN converting an empty array THEN this converts to true (just like a array with values too)
WHEN converting a function THEN this converts to true, it is truthy
WHEN converting a Date object THEN this converts to true, it is truthy
WHEN converting a RegExp object THEN this converts to true, it is truthy
Required Knowledge
- All unary operators (Unary Operators)
Related Katas
Type conversion
- to boolean
Difficulty Level
INTERMEDIATE
First Published
7 November 2023
Stats
12 tests to solve