Home > JavaScript > Empty function from php to javascript

Empty function from php to javascript


One of the most used function of php is the empty() function.
Unfortunately it’s not present in javascript and here there is the derived code.
I hope it will help you:

 

function empty (mixed_var) {
    if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || 
        mixed_var === null || mixed_var === false || 
        typeof mixed_var === 'undefined') {
        return true;
    }

    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }

    return false;
}

 

Advertisements
Categories: JavaScript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: