Skip to content

Instantly share code, notes, and snippets.

@westc
Created December 6, 2023 18:37
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 westc/b6be12b56c7a862f3a5341520221e95e to your computer and use it in GitHub Desktop.
Save westc/b6be12b56c7a862f3a5341520221e95e to your computer and use it in GitHub Desktop.
isPrimitive() - Determines if `input` is a primitive value or not.
/**
* 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