Skip to content

Instantly share code, notes, and snippets.

@DevGW
Last active April 5, 2023 14:44
Show Gist options
  • Save DevGW/39f8b5a677dedcc5e011b6797e489911 to your computer and use it in GitHub Desktop.
Save DevGW/39f8b5a677dedcc5e011b6797e489911 to your computer and use it in GitHub Desktop.
Javascript :: using switch #js
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