2021年1月25日星期一

Best practice for returning "nothing" from a ternary expression if falsy?

Similar question answered here: Assign only if condition is true in ternary operator in JavaScript

This is the ternary condition spec from mdn:

condition ? exprIfTrue : exprIfFalse

Often I find myself wanting to check if something is true, but I just want to do nothing with the falsy side of the expression. But I'm not sure how to write this:

(someVariable) ? callFunction(someVariable) : donothing but keep running the script

Should I use 'false', 'null', '', 'undefined' or something else?

The editor gives me an error if I just leave it open without anything to the right of the :

https://stackoverflow.com/questions/65895363/best-practice-for-returning-nothing-from-a-ternary-expression-if-falsy January 26, 2021 at 11:05AM

没有评论:

发表评论