0 votes
in JavaScript by
What is the precedence order between local and global variables?

1 Answer

0 votes
by

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

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