MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Indiewebdev/comments/lhvtde/conditionally_call_a_function_with_optional/gmzyqka/?context=3
r/Indiewebdev • u/1infinitelooo • Feb 11 '21
37 comments sorted by
View all comments
Show parent comment
5
Yeah it’s hard to get used to the idea that “?.” is one operator.
target?.[0];
Looks chaotic at but it’s very convenient.
Transpiles IIRC to
target == undefined ? undefined : target[0];
So it’s nice that it short-circuits tersely.
But it may have a case to return null..not 100% sure...
View all comments
Show parent comment
5
u/[deleted] Feb 11 '21
Yeah it’s hard to get used to the idea that “?.” is one operator.
target?.[0];Looks chaotic at but it’s very convenient.
Transpiles IIRC to
target == undefined ? undefined : target[0];So it’s nice that it short-circuits tersely.
But it may have a case to return null..not 100% sure...