Problem Description
Let's write a function isEmpty(value) that checks if a value is "empty." For our purposes, "empty" means it's one of the common falsy values:
undefinednull0""(empty string)false
Your function should return true if the value is falsy (empty) and false if the value is truthy (not empty).
Test Cases:
isEmpty("")should returntrueisEmpty(0)should returntrueisEmpty(undefined)should returntrueisEmpty("hello")should returnfalseisEmpty(42)should returnfalseisEmpty(true)should returnfalse
💡 The 'Syntax Nudge'
Think about the two-step process of the ! operator:
It coerces the value to its boolean equivalent. (
"hello"becomestrue,""becomesfalse).It flips that boolean.
How can you use ! to achieve the desired outcome? You might need to use it more than once. Think about what !value would give you, and what !!value would give you. Which one gets you closer to the goal?