Last active
March 29, 2019 11:05
-
-
Save dreamyguy/0efd6c6481564da9149ce0781348b0bf to your computer and use it in GitHub Desktop.
Classic value test. Shallow, not checking type nor diving into prototype.
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
// 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