||= is much needed?
brendan at mozilla.com
Thu Jun 14 11:57:53 PDT 2012
T.J. Crowder wrote:
> On 14 June 2012 19:01, Brendan Eich <brendan at mozilla.com
> <mailto:brendan at mozilla.com>> wrote:
> The users who want null to be distinct from undefined are neither
> CoffeeScript users, nor || users (in their defaulting code). They
> must be doing === undefined test.
> Not quite. I use || whenever I can in my defaulting code, and I can
> use it a lot (e.g., when the optional item must be an object). I only
> use the long-winded version if I have to because 0, "", false, or null
> is a valid possible value -- which is surprisingly rare. Hugely
> looking forward to using ?? uniformly instead, but it's not accurate
> to say that we who don't want undefined and null equated in this
> context are therefore not using ||.
Good point, when you are dealing with an object or variable that you
"know" will be either undefined or a well-typed value, you can use ||.
But how do you know what is a "possible value"?
Wes testified elsewhere that he had latent bugs. I suspect many APIs
whose impls use || do.
More information about the es-discuss