-
-
Save navanathjadhav/200b78788daeecd43c473e6afd233456 to your computer and use it in GitHub Desktop.
Example of Avoiding global varibales
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/* | |
* This will not be hoisted as global variable | |
*/ | |
function Greet() { | |
message = "Hello & Welcome to Ever Blogs"; // It will throw run time error | |
} | |
/* | |
* This will not become global variable as global functions | |
* have their own `this` in strict mode | |
*/ | |
function Greet() { | |
this.message = "Hello & Welcome to Ever Blogs"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment