Skip to main content
InterviewHubPRO
Section Overview
Q220

Question 220 of 536

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

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

What is the precedence order between local and global variables

junior LevelMost AskedCode ExampleEvent LoopPrototypes

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();