623
you are viewing a single comment's thread
view the rest of the comments
[-] ABC123itsEASY@lemmy.world 10 points 1 year ago

Yea uh is this actually equivalent? In all of those other cases you're checking if a is null and in the last case my understanding is it is checking to see if a is falsely. In the case that a is 0, or undefined, or an empty array or any other kind of non null falsey value, then the behavior would be different.

[-] Ebber@lemmings.world 21 points 1 year ago

In C# that last one is the null propagation operator. If a is not null then a, else b.

[-] ABC123itsEASY@lemmy.world 7 points 1 year ago

Ah interesting one of those cases where this could be one of a few languages. I was reading it as JS.

[-] dukk@programming.dev 3 points 1 year ago

I thought it was TS/JS too, but the way those braces are below the if statements makes it feel more like C#.

[-] darkpanda@lemmy.ca 2 points 1 year ago
[-] Rednax@lemmy.world 13 points 1 year ago

Even in Javascript, the ?? operator checks explicitly for null or undefined. So it added undefined, but not 0 or false. But adding undefined sounds like a good addition for this operator.

See the Javascript section of: https://wikipedia.org/wiki/Null_coalescing_operator#Examples_by_languages

this post was submitted on 08 Dec 2023
623 points (96.4% liked)

Programmer Humor

32745 readers
309 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS