marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Chapter 4, destructuring binding for objects #352

Closed drrckln closed 6 years ago

drrckln commented 6 years ago

Note that if the value given to such a destructuring binding is null or undefined, you get an error, much like you would if you’d directly try to access a property of those values.

This doesn't appear to be the case in the code editor. If I try the below code, destructuring on the nonexistent property "jam", it simply assigns undefined, rather than raising an error.

let {jam} = {name: "Faraji", age: 23}; console.log(jam); // -> undefined

marijnh commented 6 years ago

Try let {jam} = null. Attached patch tries to clarify this.