alongubkin / spider

Unsurprising JavaScript - No longer active
http://spiderlang.org
Apache License 2.0
1.34k stars 46 forks source link

Null coalescing operator #97

Open JoshWillik opened 9 years ago

JoshWillik commented 9 years ago

I have a couple of points about the null coalescing operator, ??.

Firstly, why isn't it still || like vanilla JS and the rest of the programming languages[1]? Changing it just for the sake of change just introduces confusion is not an improvement, IMHO.

Secondly, the ruby-esque ||= operator would be amazing.

a ||= b

becomes

a = a || b

(this can be ??= if you're quite set on keeping the ??)

[1] Except the unruly PHP

alongubkin commented 9 years ago

|| doesn't work anymore because of http://spiderlang.org/#code-safety-logical-operators-consistency

Additionally, the ?? operator checks only for undefined or null, and not all falsy values (0, false, etc).

About ??= - definitely.

M-Zuber commented 9 years ago

Am I correct in understanding that ?? based off of the c# ?? Either way the idea of ??= is a must

alongubkin commented 9 years ago

@M-Zuber Yes