When we declare a variable in JavaScript; if its declared with the var keyword it will be a local variable and if we omit the var key work it will be implicitly declared as the global variable. Developers are always careful on creating global variables.
Developers may accidentally declare global variable without their knowledge.
Solution
- function funcationName() {
- "use strict";
- };
To avoid developers from creating global variable you can use strict mode as given below. .
Conclusion
If we use strict method; when we debug we will get an exception on the line where we have declared global variables. See the screenshot below.
No comments:
Post a Comment