Проверьте, есть ли переменная ISSET JS

var status = 'Variable exists'

try {
  myVar
} catch (ReferenceError) {
  status = 'Variable does not exist'
}

console.log(status)
Difficult Dormouse