In my code I have the following:
var setTheme = function (color) {
};
function setTheme(color) {
};
The function names are not really the same but I have put the same here. Is there a difference in the two ways of creating a function?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is a difference. With a function definition, the entire definition is hoisted:
Whereas with
var, the declaration is hoisted but the assignment is not:Another difference I noticed is that on Google Chrome Canary (currently and at least, I haven’t tried in many other browsers) in ECMAScript 5 strict mode, a function definition cannot be nested more than one level deep: