Immediately invoked functions in javascript.
I have this example code:
var salary = "1000$";
(function () {
console.log("Original salary was " + salary);
var salary = "5000$";
console.log("My New Salary " + salary);
})();
I found out that the first console.log
will print undefined as the salary value.
and the second console.log will print 5000$ as the salary.
So, by executing this code, I understand that immediately invoked function get invoked in the first stage of javascript compilation when function and variables are put in variable object inside execution context. Am I right?