I’m in need to declare a local variable and test for it inside of condition of if statement. I want to be able to do it as it is possible like this, however I need to do it without global scope; is this possible?
notWorkingSofar('#element');
function notWorkingSofar(a) {
if(!(b=document.getElementById(a.slice(1)))){return b;}
else{return false;}
}
I need it to basically do this; however that gives SyntaxError.
notWorkingSofar('#element');
function notWorkingSofar(a) {
if(!(**var** b=document.getElementById(a.slice(1)))){return b;}
else{return false;}
}
Is there any other way to access or set local variables, other then by “var variable=”? Maybe by function.variable, akin to window.variable… Not sure though.
EDIT: Trying to do it inside a chain of these: (!!(b = document.getElementById(a.slice(1)))?b:[0,])
You don’t need a variable at all. You could just do:
or if you are not going to test for strict equality, even
will be fine.
If you really want a local variable than declare it with
beforehand.