Last active
February 24, 2025 09:26
-
-
Save bhaireshm/f3e08002cc67f42f5e77eb7ce606c09b to your computer and use it in GitHub Desktop.
To check whether the value of any variable is empty.
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
/** | |
* @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
ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.