If I declare variable like this,
let variable;
How to check if the variable is declared?
(If it is initilized, I will do this way..)
if (typeof variable !== 'undefined') { }
You can catch ReferenceError to check if the variable is declared or not.
var declared = true;
try{
theVariable;
}
catch(e) {
if(e.name == "ReferenceError") {
declared = false;
}
}
declared = false; in the catch.