const Person = (name) => {
const sayName = () => console.log(`my name is ${name}`)
return {sayName}
}
( Is this same as )
function Person () {
function sayName () {
return(console.log(`my name is ${name}`))
//IS THIS RIGHT?
return {sayName}
}
1 Like
jainashish0712:
( Is this same as )
Yes, except you’ve missed out a closing curly bracket on the inner function. There’s not really much to explain, in this context they’re exactly the same
2 Likes
In the second one name
is referenced, but isn’t declared as a parameter.
2 Likes
One is arrow function, while the other is not.
By the way you don’t have to put the curly brackets {} in the return.
return sayName;
Should work.
1 Like