3 ms·
Hmm, that's annoying behaviour. This doesn't give a runtime error: var [a,b,c] = [1] Either way, I'd highly recommend just using TypeScript.
by seanwilson 8y ago
Hmm, that's annoying behaviour. This doesn't give a runtime error:
var [a,b,c] = [1]
Either way, I'd highly recommend just using TypeScript.
- vimslayer 8y agoRight, because while b and c will be undefined, they are taken from an existing array, not from null/undefined. This will throw var [a, b, c] = null and this (destructing a nested array) var [[a]] = [] the point of the "elvis" ?. operator is to make accessing properties _of_ optional values or other optional properties easier. "Either way, I'd highly recommend just using TypeScript." Sure, I'd recommend that too, but in this case it "only" helps us by moving the error from runtime to compile-time, nested optional property access remains ugly in the TS world, too. The ?. operator will come to TypeScript as soon as it comes to EcmaScript.