Re:%20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re:%20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Sebastian Cholewa

It’s still longer than `??` but instead of:

`(u !== undefined && u !== null) ? u : 0`

one can use:

`u != null ? u : 0`






_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: %20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Naveen Chawla
I prefer `u || 0`

On Thu, 21 Dec 2017 at 13:56 Sebastian Cholewa <[hidden email]> wrote:

It’s still longer than `??` but instead of:

`(u !== undefined && u !== null) ? u : 0`

one can use:

`u != null ? u : 0`





_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: %20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Michael Rosefield
Yes, but that conflates falsey values; `??` *should* be about recognising whether values *exist*, not whether they are *truthy*.

On Thu, 21 Dec 2017 at 12:20 Naveen Chawla <[hidden email]> wrote:
I prefer `u || 0`

On Thu, 21 Dec 2017 at 13:56 Sebastian Cholewa <[hidden email]> wrote:

It’s still longer than `??` but instead of:

`(u !== undefined && u !== null) ? u : 0`

one can use:

`u != null ? u : 0`





_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: %20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Naveen Chawla
Typically `||` is sufficient. Yes if you want to allow empty strings and/or 0, you would need to add checks for those to the left of the `||`, but I'm not sure that's a bad thing to require in JavaScript.

The nullish conditional operator, however ( `?.` and `?[`) , I think is a bigger addition to the language.

On Thu, 21 Dec 2017 at 18:05 Michael Rosefield <[hidden email]> wrote:
Yes, but that conflates falsey values; `??` *should* be about recognising whether values *exist*, not whether they are *truthy*.

On Thu, 21 Dec 2017 at 12:20 Naveen Chawla <[hidden email]> wrote:
I prefer `u || 0`

On Thu, 21 Dec 2017 at 13:56 Sebastian Cholewa <[hidden email]> wrote:

It’s still longer than `??` but instead of:

`(u !== undefined && u !== null) ? u : 0`

one can use:

`u != null ? u : 0`





_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: %20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Sebastian Cholewa

I do like the idea of `??`, I only wanted to point out that sticking to `x !== null && x !== undefined` is not needed. After all, `null == undefined` only to each other. The rules of soft comparison are known and won’t be changed, so let’s take advantage of them while awaiting for `??`.

Od: "Naveen Chawla" <[hidden email]>
Do: "Michael Rosefield" <[hidden email]>;
Wysłane: 15:36 Czwartek 2017-12-21
Temat: Re: %20Re%3A%20Looking%20for%20Champion%3A%20Null%20Coalescing%20%28%3F%3F%29%20and%20Null%20Conditional%0A%09Member%20Access%20%28%3F.%29%20operators&In-Reply-To=%3CCAAuY5VfQ7bDx%3D3LVPsNf78jbDFHqYkK%2BQgMui9EgsqQOSQ0%3DKw%40mail.gmail.com%3E

Typically `||` is sufficient. Yes if you want to allow empty strings and/or 0, you would need to add checks for those to the left of the `||`, but I'm not sure that's a bad thing to require in JavaScript.

The nullish conditional operator, however ( `?.` and `?[`) , I think is a bigger addition to the language.

On Thu, 21 Dec 2017 at 18:05 Michael Rosefield <[hidden email]> wrote:
Yes, but that conflates falsey values; `??` *should* be about recognising whether values *exist*, not whether they are *truthy*.

On Thu, 21 Dec 2017 at 12:20 Naveen Chawla <[hidden email]> wrote:
I prefer `u || 0`

On Thu, 21 Dec 2017 at 13:56 Sebastian Cholewa <[hidden email]> wrote:

It’s still longer than `??` but instead of:

`(u !== undefined && u !== null) ? u : 0`

one can use:

`u != null ? u : 0`





_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss