Created
December 6, 2023 18:37
-
-
Save westc/b6be12b56c7a862f3a5341520221e95e to your computer and use it in GitHub Desktop.
isPrimitive() - Determines if `input` is a primitive value or not.
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
/** | |
* Determines if `input` is a primitive value or not. | |
* @param {any} input | |
* The input value to test. | |
* @returns {boolean} | |
* Returns `true if `input` is a primitive, otherwise `false` is returned. | |
*/ | |
function isPrimitive(input) { | |
if (input == null) { | |
// This is here to correctly handle document.all. | |
return input === null || input === undefined; | |
} | |
const type = typeof input; | |
return type !== "object" && type !== "function"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment