JavaScript Verifique se a variável existe
if (typeof myVar !== 'undefined') {
// myVar is defined
}
Grepper
if (typeof myVar !== 'undefined') {
// myVar is defined
}
if (typeof variable === 'undefined') {
// variable is undefined
// eg:
// var variable = "someValue";
}
var status = 'Variable exists'
try {
myVar
} catch (ReferenceError) {
status = 'Variable does not exist'
}
console.log(status)