Reputation: 3548
Beginner here. Why userName
is undefined
in the function and how to make the function to have it as John Doe and not undefined
?
const userName = 'John Doe';
console.log(userName);
const loggedInUser = (userName) => console.log('Logged in user is: ' + userName);
loggedInUser();
Console output:
index.js:22 John Doe
index.js:23 Logged in user is: undefined
Upvotes: 0
Views: 3989
Reputation: 11182
const loggedInUser = (userName) => console.log('Logged in user is: ' + userName);
defines a function named loggedInUser
that takes a single argument.
After defining this function you call it on the next line loggedInUser();
, but you don't provide the argument.
Try loggedInUser(userName);
Upvotes: 1