Implement nullish coalescing operator (??) #1894

Closed
opened 3 months ago by Moonchild · 2 comments
Owner

ES2020 standards proposal, used in the wild.

ES2020 standards proposal, used in the wild.
Moonchild added the
Javascript
Enhancement
Standards Compliance
Web Compatibility
labels 3 months ago
Moonchild added a new dependency 3 months ago
Poster
Owner

Sajadi wrote:

Perhaps this could be somehow useful or as a base to implement
"nullish coalescing operator (??)

Its from the Waterfox Classic Repo

https://github.com/WaterfoxCo/Waterfox-Classic/pull/101

Sajadi wrote: > Perhaps this could be somehow useful or as a base to implement > "nullish coalescing operator (??) > > Its from the Waterfox Classic Repo > > https://github.com/WaterfoxCo/Waterfox-Classic/pull/101
Poster
Owner

Tested and verified the code in #1901 as working as intended with the following snippet of code (combining also optional chaining):

foo = { someFooProp: "hi" };

console.log(foo.someFooProp?.toUpperCase() ?? "not available"); // HI         
console.log(foo.someBarProp?.toUpperCase() ?? "not available"); // not available

console.log(0 || 42); // 42
console.log(0 ?? 42); // 0
console.log(true && false); // false
console.log(true && true); // true
console.log((true && false) || 42); // 42
console.log((true && false) ?? 42); // false

As well as tested that true && false ?? 42 without parenthesizing is a syntax error, as that is not allowed due to ambiguity.

Tested and verified the code in #1901 as working as intended with the following snippet of code (combining also optional chaining): ```JavaScript foo = { someFooProp: "hi" }; console.log(foo.someFooProp?.toUpperCase() ?? "not available"); // HI console.log(foo.someBarProp?.toUpperCase() ?? "not available"); // not available console.log(0 || 42); // 42 console.log(0 ?? 42); // 0 console.log(true && false); // false console.log(true && true); // true console.log((true && false) || 42); // 42 console.log((true && false) ?? 42); // false ``` As well as tested that `true && false ?? 42` without parenthesizing is a syntax error, as that is not allowed due to ambiguity.
Moonchild added the
Fixed
Verified
Bounty
labels 3 months ago
Moonchild closed this issue 3 months ago
Moonchild added the
Bounty paid
label 3 months ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Blocks
#1734 Implement ES2020 proposals
MoonchildProductions/UXP
Reference: MoonchildProductions/UXP#1894
Loading…
There is no content yet.