Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Last active April 22, 2021 14:13
Show Gist options
  • Save bhaireshm/f3e08002cc67f42f5e77eb7ce606c09b to your computer and use it in GitHub Desktop.
Save bhaireshm/f3e08002cc67f42f5e77eb7ce606c09b to your computer and use it in GitHub Desktop.
To check whether the value of any variable is empty.
/**
* @param data - any datatype value.
*/
function isEmpty(data) {
if (typeof data == "number" || typeof data == "boolean") return false;
if (typeof data == "undefined" || data === null) return true;
if (typeof data.length != "undefined") return data.length == 0;
let count = 0;
for (let i in data) if (data.hasOwnProperty(i)) count++;
return count == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment