...

/

Solution Review: Destructure Undefined

Solution Review: Destructure Undefined

This lesson will explain the solution to the problem in the previous lesson.

The challenge in the previous lesson requires you to fix the following code using your understanding of object destructuring.

Press + to interact
function pointValues(point){
const {name:n,age:a} = point
console.log(n)
console.log(a)
}
var point = {name:"jerry", age: 2}
pointValues(point)
point = undefined
pointValues(point)

Solution 1 #

Press + to interact
function pointValues(point){
const {name:n,age:a} = {...point}
console.log(n)
console.log(a)
}
pointValues({name:"jerry", age:2})
pointValues(undefined)

Explanation #

...
Access this course and 1400+ top-rated courses and projects.