check if variable is defined javascript code example
Example 1: javascript check if variable exists
if (typeof myVar !== 'undefined') {
// myVar is defined
}
Example 2: check if isset variable js
var status = 'Variable exists'
try {
myVar
} catch (ReferenceError) {
status = 'Variable does not exist'
}
console.log(status)
Example 3: How can I check whether a variable is defined in Node Js
if (query){
doStuff();
}