Some parts of each of these answers work. I compiled them all down into a function "isset" just like the question was asking and works like it does in PHP.
// isset helper function var isset = function(variable){ return typeof(variable) !== "undefined" && variable !== null && variable !== ''; }
Here is a usage example of how to use it:
var example = 'this is an example';
if(isset(example)){
console.log('the example variable has a value set');
}
It depends on the situation you need it for but let me break down what each part does:
typeof(variable) !== "undefined"
checks if the variable is defined at allvariable !== null
checks if the variable is null (some people explicitly set null and don't think if it is set to null that that is correct, in that case, remove this part)variable !== ''
checks if the variable is set to an empty string, you can remove this if an empty string counts as set for your use caseHope this helps someone :)