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?

0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.