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 :
没有评论:
发表评论