hierarchial object destructuring in js code example

Example 1: destructured object

let renseignement = ['voleur' , '10' , 'spécialité'] ;


let [classe , force, magie] = renseignement ;

console.log(classe) ;
console.log(force) ;
console.log(magie) ;

Example 2: js object destructuring with defaults

// Taken from top stack overflow answer

const { dogName = 'snickers' } = { dogName: undefined }
console.log(dogName) // what will it be? 'snickers'!

const { dogName = 'snickers' } = { dogName: null }
console.log(dogName) // what will it be? null!

const { dogName = 'snickers' } = { dogName: false }
console.log(dogName) // what will it be? false!

const { dogName = 'snickers' } = { dogName: 0 }
console.log(dogName) // what will it be? 0!