If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

And the result is 2 alerts.
The first one (and the expected one) with the legend "a=1, b=2"
And a second one with the legend "undefined";

Why this second alert?

Function declarations are read and available in an execution context before any code is exectued, whereas function expressions aren't executed until the execution reaches that line of code. JS engine pulls function declarations to the top of the source tree through a process known as function declaration hoisting.

This example shows difference between function declarations and function expressions: