Problem Description
Write a function toggleSwitch(isOn) that takes a single boolean value (true or false) representing the state of a light switch. Your function should return the new state of the switch.
Test Cases:
toggleSwitch(true)should returnfalsetoggleSwitch(false)should returntrue
馃挕 The 'Syntax Nudge'
This one is a direct application of the operator. How can you use ! on the isOn argument to return the opposite value?
The Logical NOT ! is a unary operator because it only works on one operand (the value right after it).
Its job is simple:
It takes any value.
It coerces (converts) that value into its "truthy" or "falsy" boolean equivalent.
It flips that boolean.
!truebecomesfalse!falsebecomestrue!"hello"(a "truthy" string) becomesfalse!0(a "falsy" number) becomestrue