Is there a universal JavaScript function that checks that a variable has a value and ensures that it\'s not undefined or null? I\'ve got this code,
undefined
null
You are a bit overdoing it. To check if a variable is not given a value, you would only need to check against undefined and null.
function isEmpty(value){ return (typeof value === "undefined" || value === null); }
This is assuming 0, "", and objects(even empty object and array) are valid "values".
0
""