It's so much easier than programming. Login and vote now.
By bloid
via blog.quinthar.com
Published: Jul 02 2008 / 18:03
In any reasonable language, it would first alert "Hello", and then alert "World". But noooo. Javascript's gotta get all fancy and defer execution until later. And at that point message is equal to "World" for both. So it's "World" "World", which ain't right at all.
SaveShareSend
Tags: javascript, opinion
Comments
kenman replied ago:
Was good for a laugh.
unchqua replied ago:
But this can be useful if you know this feature and use it wisely.
Kenneth Downs replied ago:
I voted up because the article opens the discussion of the behavior of anonymous functions, which can be counter-intuitive if you are used to other languages.
willcode4beer replied ago:
JavaScript didn't defer execution, the author did by putting the calls to the functions at the end.
He's apparently confused that the global variable 'message' is.... global.
Voters For This Link (7)
Voters Against This Link (13)