简体   繁体   中英

Using return in shorthand if statement doesn't work

I can't seem to understand why does this work:

if(n < i)
{
    functoin();
}
else
{
    return;
}

While this doesn't work:

(n < i) ? function() : return;

why does the shorthand if-statement doesn't work?

return can't be used in an expression. Maybe you can try,

return (n < i) ? function() : undefined;

But that's only if you have one thing to do for each condition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM