I'm a little confused over the execution flow of self invoking functions in javascript.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var test = function () {
alert("Test1##");
}
var test2 = function () {
alert("Test2!!");
}
(function () {
test();
})();
</script>
</body>
</html>
Result: Test2!!
.
I expected it to alert Test1##
since I'm calling that particular function.
However, if I include semicolon after each functions test
and test2
, the result is how I expect it to be: It would alert Test1##
.
How does it work?