4 ms·
But: functionOne = function() { // Some code }; (i.e. without the var) is represented same as: function functionTwo() { // Some code } is i
by yiedyie 12y ago
But:
functionOne = function() {
// Some code
};
(i.e. without the var) is represented same as:
function functionTwo() {
// Some code
}
is it?
- LunaSea 12y agoNo, with or without the var doesn't change the fact that it is still a variable declaration. Without the "var" keyword, you just created a global variable rather than one restricted to your local scope.
- jaredmcateer 12y agoThe function declaration is still restricted to the scope it's within. The problem is that the function declaration does some additional hoisting magic nothing else gets. If you declare a variable in the middle of a function the variable name gets hoisted but the value does not. If you declare a function in the middle of another function the name gets hoisted but so does the value. This can lead to some additional quirkiness, which is why it's recommended to use the expression assigned ot a variable, to maintain consistency.
- sarink 12y ago+99999