I want to check if a variable is defined before using it, so I wrote something like this
if(!variable){
return null;
}
But it throws an error
ReferenceError: variable is not defined
If I do it like this
if(typeof variable === 'undefined'){
return null;
}
It works as expected.
What is the difference between the approaches and why it didn't return null in the first example but instead it died with the error ?