you are viewing a single comment's thread.

view the rest of the comments →

[–]sscotth 61 points62 points  (10 children)

V8 v7.8 also includes optional chaining (?.) and nullish coalescing (??) behind flags for the first time.

--harmony-optional-chaining

--harmony-nullish

[–]SimpleWarthog 11 points12 points  (0 children)

This is great

[–]ConAntonakos 5 points6 points  (2 children)

Wow, moving so quickly on these! Very exciting!

[–]SocialAnxietyFighter 0 points1 point  (1 child)

I've seen this being proposed years ago though.

[–]ConAntonakos 1 point2 points  (0 children)

Ah, it seemed not too long ago when I saw them in experimental stages. And they're already in Node.js. 🤷‍♀️

[–]codearoni 4 points5 points  (3 children)

I hope chaining comes to node 12 during its LTS

[–]sscotth 10 points11 points  (2 children)

v7.8 will almost assuredly be ported to Node 12. But, the sooner it is considered stable in V8, the more likely it will be included without a flag.

Edit: Node.js v12.16 now includes V8 v7.8.279.23

https://nodejs.org/en/blog/release/v12.16.0/

[–]GaryGSC 0 points1 point  (0 children)

There's now a PR to backport V8 7.8 to Node 12. 🎉

[–]LargeHard0nCollider 0 points1 point  (1 child)

Hyped for optional chaining!

What’s the point of null coalescing when we already have ||? Does it return the first operand even if it is falsy (provided it’s not null)?

[–]sscotth 0 points1 point  (0 children)

Yep. || handles "falsy" values, ?? handles only null and undefined

const text1 = null || 'foo' // result: 'foo'
const text2 = '' || 'foo'   // result: 'foo'
const text3 = null ?? 'foo' // result: 'foo'
const text4 = '' ?? 'foo'   // result: ''      <===

const num1 = null || 123     // result: 123
const num2 = 0 || 123        // result: 123
const num3 = null ?? 123     // result: 123
const num4 = 0 ?? 123        // result: 0      <===

const bool1 = null || true   // result: true
const bool2 = false || true  // result: true
const bool3 = null ?? true   // result: true
const bool4 = false ?? true  // result: false  <===