LOGIN
Ali Stone
Official Community Moderator (Decision maker on who becomes Verified Freelance Talent)
Ali Stone
9
Official Community Moderator (Decision maker on who becomes Verified Freelance Talent)
· New York, NY, United States
QUESTION

Question posted by collaborizm workspace (slackbot)

Need help on a javascript quiz…

1 like
Like
Award Contribution
Load previous comments
Ranjan Dailata
92
Solution Architect. Collaborizm Roundtable.
· Mysuru, Karnataka, India

The first one being a function that’s declared, doesn’t matter whether you do it first or not. But the second approach is a function expression created using var, much like an ordinary variable being created. This is the case of a function reference stored within the variable. Hence you cannot call these ahead of the time as you are creating the function expression at the later point.

Like
Award Contribution
Ali Stone
9
Official Community Moderator (Decision maker on who becomes Verified Freelance Talent)
· New York, NY, United States

but in question one, the function is called BEFORE it’s declared too…that’s why it’s undefined?

Like
Award Contribution
Ranjan Dailata
92
Solution Architect. Collaborizm Roundtable.
· Mysuru, Karnataka, India

The undefined log that you are seeing is because of the variable not defined and initialized at first. It’s not same as not a function. Although the code looks almost same but they are not. It works in a totally different way as they are written.

console.log(greeting);
var greeting = ‘Hello!’;

Like
1 like
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
Chat with us!
Help
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard