const person = (firstName, lastName) =>
{
first: firstName,
last: lastName
}
console.log(person("Jill", "Wilson"))
This code get a syntax error Please let me know the correct code Thanks
const person = (firstName, lastName) =>
{
first: firstName,
last: lastName
}
console.log(person("Jill", "Wilson"))
This code get a syntax error Please let me know the correct code Thanks
Wrap your object in brackets (). It is required if you are returning anonymous object right in arrow function.
const person = (firstName, lastName) =>
({
first: firstName,
last: lastName
})
console.log(person("Jill", "Wilson"))
It could not be possible to find difference between function and object. This is function in curly brackets:
const myFn = () => {
const someCode = "wow I'm in function. Not in Object!";
}
It has same syntax, same brackets, as the example you have provided.