Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. // Global scope
  2.  
  3. function sayHello () {
  4. // Local scope 1
  5.  
  6. var greet = 'Hello!' // Scoped to local scope 1
  7. console.log('1: ', greet) // Accessible from local scope 1
  8. }
  9.  
  10. function changeGreet () {
  11. // Local scope 2
  12.  
  13. console.log('2: ', greet) // NOT Accessible from local scope 2
  14. }
  15.  
  16. sayHello()
  17. changeGreet()
  18.  
  19. // 1: Hello!
  20. // ReferenceError: greet is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement