Is there a better way to write this code? i tried function(){}(); but i got an error so i had to use DUMMY as a placeholder var. The function should run before alert b does. Whats a better way of writing this?
var DUMMY = function(){
var names = "i dont want to be seen";
alert('A');
}; DUMMY();
alert('B');
I actually use the syntax you say doesn’t work all the time. The thing is, you need to either store the return value, or make it an expression. So either:
or
Note the difference between Pointy’s answer on this one. The expression is the entire function (including the calling
()), not just the function declaration. Either way will do the same thing. Use what you feel is more readable (Personally I like this syntax better, but to each their own)…