Javascript parse/evaluation order?

Posted by Breck Fresen on Stack Overflow See other posts from Stack Overflow or by Breck Fresen
Published on 2010-04-30T03:54:14Z Indexed on 2010/04/30 4:07 UTC
Read the original article Hit count: 415

Filed under:

This is probably a nub question, but I don't understand why this works:

<script type="text/javascript">
    alert(foo);
    function foo() { }
</script>

This alerts "function foo() { }", but I expected the alert to be evaluated before the function foo was defined. Can someone explain what I don't understand about parse/evaluation order or point me to a resource that does?

Thanks in advance,

-- Breck

© Stack Overflow or respective owner

Related posts about JavaScript