Reputation:
Why does this code :
const horn = () => {
console.log("Toot");
};
console.log(horn())
prints Toot Undefined
Where does undefined comes from?
Upvotes: 0
Views: 53
Reputation: 49
If you want log in your function, just call horn.
const horn = () => {
console.log("Toot");
};
horn();
Upvotes: 0
Reputation: 1140
You are trying to print the return (result) of the function. Even though your function does something inside, it has no return statement (aka doesn't send a result back), therefore you get undefined. If you want to get only 1 "Toot", try this:
const horn = () => {
return "Toot";
};
console.log(horn());
Upvotes: 1