Skip to content

Instantly share code, notes, and snippets.

View SeanBannister's full-sized avatar

Sean Bannister SeanBannister

View GitHub Profile
@SeanBannister
SeanBannister / isEmpty.js
Last active May 9, 2020 05:49
Check if a variable/array/object is empty/null/undefined/etc in javascript.
function isEmpty(value) {
// If any of these return true this function returns true.
return (
// Null or undefined.
(value == null) ||
// Check if a Set() or Map() is empty
(value.size === 0) ||
// NaN - The only JavaScript value that is unequal to itself.
(value !== value) ||
// Length is zero && it's not a function.