I’m trying to learn destructuring to create an object from function inputs. I’d do it like this normally:
const createContact = (name, email, phone) => {
const newContact = {
name: name,
email: email,
phone: phone
};
console.log(newContact);
};
createContact("virge", "[email protected]", "1234555555");
But when I try to assign these values using destructuring I get an error “Identifier ‘name’ has already been declared.”
const createContact = (name, email, phone) => {
const { name, email, phone } = newContact;
console.log(newContact);
};
createContact("virge", "[email protected]", "1234555555");
How can I fix this?