JAVASCRIPT ES6 DESTRUCTURING AND A FEW USEFUL TRICKS
Djamel Hassaine
81

Hi,

I was trying your statement for destructuring:

const {data: {hits: {hits: results = []}} = {}} = response

with the data:

const response = {
data: {
hits:{
hits: {
results: [{
“name”: “Dave”
}]
}
}
}
}

However if you change the data to

const response = {
data: {
hitswrongprop:{
hits: {
results: [{
“name”: “Dave”
}]
}
}
}
}

It doesn’t perform in the same way that the defensive technique does. It blows up when one of the properties is renamed.

Like what you read? Give wongcheming a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.