InterviewHubPRO
Section Overview
Q220

Question 220 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

42%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

What is the precedence order between local and global variables

A local variable takes precedence over a global variable with the same name. Let's see this behavior in an example.

javascript
  var msg = "Good morning";
  function greeting() {
    msg = "Good Evening";
    console.log(msg); // Good Evening
  }
  greeting();