syntax - In CoffeeScript, what is the existential operator for and how do you use it? -
this question has answer here:
i see sorts of questions existential operator on so, none of them ask fundamental question of "what for" , "how use it?" thought i'd ask here.
the answer here suffice answer question, problem question title doesn't suggest that. result, it's hard find question google search. so, intention here make easier learn operator google search.
btw, aware of section in the little book on coffeescript titled "aliases & existential operator", reason don't explanation. doesn't make me feel "i it".
the existential operator provides more concise , expressive way handle null
, undefined
properties.
instead of
if (user && user.url && user.url.indexof('foo'))
you can do
if user?.url?.indexof 'foo'
instead of
if (baker.bakebread) { baker.bakebread()}
you can coffeescript
baker.bakebread?()
Comments
Post a Comment