0
const contatos = [
{
nome: 'Alex Júnior',
numero: '1234-5678'
},
{
nome: 'Carolina Moya',
numero: '1234-6789'
},
{
nome: 'Fernando Jorge',
numero: '12345-5567'
}
];
const [Alex , Carol] = contatos;
function mostraNumero({numero}){ // aqui mora a dúvida
console.log(numero)
}
mostraNumero(Carol);
When executing the code, when calling the function mostraNumero()
:
When invoked mostraNumero(Carol)
, soon (Carol)
----> ({numero})
becomes the parameter. Summarizing:
Carol = {
nome: 'Carolina Moya',
numero: '1234-6789'
}
As just writing {numero}
has already been able to access the property and value, after (numero
) accesses the direct value. I thought I had to use the dot notation (.
) to access a property. Someone can clarify for me?