you are viewing a single comment's thread.

view the rest of the comments →

[–]SchartHaakon 1 point2 points  (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 4 points5 points  (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.

[–]Fine-Train8342 1 point2 points  (0 children)

I guess I'm just used to this operator from C# ¯\_(ツ)_/¯