Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, 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.



The 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.


+99999




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: