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
The first answer with best rating is wrong. If value is undefined it will throw an exception in modern browsers. You have to use:
if (typeof(value) !== "undefined" && value)
or
if (typeof value !== "undefined" && value)