I know that you can do this:
function first(a){
a && console.log("true");
}
which is the same as:
function first(a){
if(a){
console.log("true");
}
}
However, when I tried this:
function first(a){
a && return false
}
It doesn’t work, and it throws me an error. Why is it giving me an error?
returncan only be used in a statement on its own.In
a && return falseit would be part of an expression, which is syntactically wrong.