Guest User

Untitled

a guest
Jan 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. //variable in the global scope
  2. var globalVariable = "Global Variable";
  3.  
  4. var newLexicalScope = function() {
  5.  
  6. var localVariable = "Local Variable";
  7.  
  8. //variables that can be accessed in this scope are globalVariable, localVariable, newScopeVariable
  9. console.log(localVariable);
  10.  
  11. //Javascript adds these variables without var declaration to the global scope [DONOT DO IT].
  12. localVariableWithoutDeclaration = "Local Variable Without Declaration";
  13.  
  14. };
  15.  
  16. newLexicalScope();
  17.  
  18. //Both globalVairable and localVariableWithoutDeclaration shall be printed to console
  19. console.log(globalVariable);
  20. console.log(localVariableWithoutDeclaration);
Add Comment
Please, Sign In to add comment