Can I execute functions this way?
const test = testFunc() // returns "value" or undefined
test && anotherFunction()
Basically I want to execute anotherFunction()
if test const is defined, otherwise just skip it.
I know that I can use something like this:
if (test) {
anotherFunction()
}
but I'm interested why the first method isn't working.
I will appreciate if someone explain me the difference between if () {}
and &&
.
// I'm confused because if I trying to use the first method I get:
Expected an assignment or function call and instead saw an expression
in my IDE.