Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Last active March 29, 2019 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamyguy/0efd6c6481564da9149ce0781348b0bf to your computer and use it in GitHub Desktop.
Save dreamyguy/0efd6c6481564da9149ce0781348b0bf to your computer and use it in GitHub Desktop.
Classic value test. Shallow, not checking type nor diving into prototype.
// https://codesandbox.io/s/ykmo8wp63v
const isNull = null;
const isNullNumber = 0;
const isUndefined = undefined;
const isEmptyString = '';
const isNegativeNumber = -1;
const isEmptyArray = []; // shallow test
const isEmptyObject = {}; // shallow test
const isUndefinedString = 'undefined';
const isDefinedNumber = 42;
const testValue = v => v ? 'yup' : 'nope';
console.log(testValue(isNull)); // nope
console.log(testValue(isNullNumber)); // nope
console.log(testValue(isUndefined)); // nope
console.log(testValue(isEmptyString)); // nope
console.log(testValue(isNegativeNumber)); // yup
console.log(testValue(isEmptyArray)); // yup
console.log(testValue(isEmptyObject)); // yup
console.log(testValue(isUndefinedString)); // yup
console.log(testValue(isDefinedNumber)); // yup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment