JS Coding Questions Logo
JS Coding Questions
#216💼 Interview💻 Code

What is the precedence order between local and global variables

Advertisement

728x90

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

javascript
1var msg = "Good morning";
2
3function greeting() {
4  msg = "Good Evening";
5  console.log(msg); // Good Evening
6}
7
8greeting();

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 46

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
216of476
What is the precedence order between local and global variables | JSCodingQuestions.com