0

I have noticed that when coding in javascript, it doesn't matter if i declare the function before or after i call it. In other languages it will cause an exception, but when running javascript in chrome it works just fine. Is that only in chrome, or is that normal?

arielschon12
  • 6,016
  • 11
  • 36
  • 50

1 Answers1

2

What you're seeing is function hoisting in action: http://elegantcode.com/2011/03/24/basic-javascript-part-12-function-hoisting

pdoherty926
  • 10,116
  • 2
  • 34
  • 61
  • 1
    Basically, setting it as a variable makes the function only work after the variable is set, and declaring it with the function keyword directly makes it accessible from anywhere, anytime. – SeinopSys Feb 25 '13 at 20:11