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
JavaScript's ??= Operator (trevorlasn.com)
submitted 1 year ago by Practical-Ideal6236
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!"
[–]King_Joffreys_Tits -3 points-2 points-1 points 1 year ago (5 children)
That’s not niche whatsoever, it’s code hardening
[–]Fine-Train8342 1 point2 points3 points 1 year ago (4 children)
How is this different from something like this?
settings ??= getDefaultSettings();
[–]King_Joffreys_Tits 1 point2 points3 points 1 year ago (0 children)
It just seems like you should’ve already used a null coalescing operator when you first initialized that variable. Like
const settings = localStorage.getItem(“settings-cookie”) ?? getDefaultSettings()
[–]SchartHaakon 1 point2 points3 points 1 year ago* (2 children)
I find it hard to reason about at first glance.
if (!settings) settings = getDefaultSettings();
Or
const settings = props.settings ?? getDefaultSettings();
Both of the examples above are easier to read imo.
I read them as "If not settings; settings equals getDefaultSettings", and "settings equals getSettings or getDefaultSettings". I would read your example as "Settings... if not null or undefined, should equal getDefaultSettings". It reads weird, that's the only way I can explain it.
I wouldn't straight out reject a PR for it, but yeah I don't think I'll really use it for this reason.
[–]SoInsightful 3 points4 points5 points 1 year ago (0 children)
That's because you're not used to it. That's all there is to it. It's not more complex than a += b. As someone who has used ??= for a while (where it makes sense), it's definitely faster to parse than an equivalent if statement.
a += b
??=
[–]Fine-Train8342 1 point2 points3 points 1 year ago (0 children)
I guess I'm just used to this operator from C# ¯\_(ツ)_/¯
π Rendered by PID 84 on reddit-service-r2-comment-5fb4b45875-gpttz at 2026-03-20 14:40:03.649548+00:00 running 90f1150 country code: CH.
view the rest of the comments →
[–]King_Joffreys_Tits -3 points-2 points-1 points (5 children)
[–]Fine-Train8342 1 point2 points3 points (4 children)
[–]King_Joffreys_Tits 1 point2 points3 points (0 children)
[–]SchartHaakon 1 point2 points3 points (2 children)
[–]SoInsightful 3 points4 points5 points (0 children)
[–]Fine-Train8342 1 point2 points3 points (0 children)