I ran this and get "undefined", "11", "12".
I haven't figured out why you're getting "undefined", but x is set to 10 at that point, so the next time you call it, it gets set to 11, and the next time it gets set to 12.
function foo() {
alert(bar())
}...