Last active
April 5, 2023 14:44
-
-
Save DevGW/39f8b5a677dedcc5e011b6797e489911 to your computer and use it in GitHub Desktop.
Javascript :: using switch #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isTruthy = (anArg) => { | |
if (anArg) return true; | |
switch (anArg) { | |
case false: | |
return 'The boolean value false is falsey'; | |
case null: | |
return 'The null value is falsey'; | |
case undefined: | |
return 'undefined is falsey'; | |
case 0: | |
return 'The number 0 is falsey (the only falsey number)'; | |
case '': | |
return 'The empty string is falsey (the only falsey string)'; | |
default: | |
return 'NaN is falsey.'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment