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 CodingAdvertisement
728x90
216of476