Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variable in the global scope
- var globalVariable = "Global Variable";
- var newLexicalScope = function() {
- var localVariable = "Local Variable";
- //variables that can be accessed in this scope are globalVariable, localVariable, newScopeVariable
- console.log(localVariable);
- //Javascript adds these variables without var declaration to the global scope [DONOT DO IT].
- localVariableWithoutDeclaration = "Local Variable Without Declaration";
- };
- newLexicalScope();
- //Both globalVairable and localVariableWithoutDeclaration shall be printed to console
- console.log(globalVariable);
- console.log(localVariableWithoutDeclaration);
Add Comment
Please, Sign In to add comment