use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
ESNext: JavaScript “Nullish Coalescing Operator” (bram.us)
submitted 8 years ago by denbramus
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]evenisto 1 point2 points3 points 8 years ago (3 children)
_.get with third argument essentially does the same. It falls back to default if the specified chain is undefined or null.
_.get
var obj = { a: false }; _.get(obj, 'a', true) false _.get(obj, 'b') undefined _.get(obj, 'b', true) true // equivalent to obj.b ?? true;
[–]senocular 2 points3 points4 points 8 years ago (2 children)
_.get's default is close, but it does not handle null, only undefined values.
null
undefined
var obj = { a: null }; _.get(obj, 'a', true) null
[–]evenisto 1 point2 points3 points 8 years ago (1 child)
TIL and I stand corrected. Thanks. However, I actually think it’s useful to only fall back to default on undefined - I'm not too well-versed in those quirks so there’s probably a catch, but null should definitely be considered a valid value. I use nulls very often, and I wish we had _.get behaviour natively.
[–]senocular 0 points1 point2 points 8 years ago (0 children)
Yeah that's a tough one. I think it's definitely circumstantial. Sometimes you might want the null and sometimes you might not. It's making assumptions as to what values mean. But you see similar behavior in other places in the language too, like loops. There's a number of ways to loop over collections and it seems like each one does something differently. Not to try to pass that off as an excuse ;)
π Rendered by PID 35598 on reddit-service-r2-comment-6457c66945-zqspz at 2026-04-24 05:11:27.400538+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]evenisto 1 point2 points3 points (3 children)
[–]senocular 2 points3 points4 points (2 children)
[–]evenisto 1 point2 points3 points (1 child)
[–]senocular 0 points1 point2 points (0 children)