JavaScript - Hoisting

javascript

// JavaScript - Variable and function hoisting:

var salary = "1000$";
(function () {
  console.log("Original salary was " + salary);
  var salary = "5000$";
  console.log("My New Salary " + salary);
})();

The above code log 'undefined, 5000$' to the console.  This is due to variable
hoisting.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License