Why does the regular assignment statement (say, x = 5
) return the value assigned (5
in this case), while the assignment combined with a variable declaration (var x = 5
) returns undefined
?
I got the return values by executing these statements in the Chrome browser's Javascript console:
> var x = 5;
undefined
> y = 5;
5