Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. const x = 'const';
  2. const x = 'not-const';
  3.  
  4. Will give an error: 'constant 'x' has already been defined'
  5.  
  6. const x = 'const';
  7. x = 'not-const';
  8.  
  9. // will output 'SECRET'
  10.  
  11. const x = 'SECRET'
  12. if (x = 'ANOTHER_SECRET') { // Warning! assigining a value variable in an if condition
  13. console.log (x)
  14. }
  15.  
  16. // will output 'ANOTHER_SECRET'
  17.  
  18. var y = 'SECRET'
  19. if (y = 'ANOTHER_SECRET') {
  20. console.log (y)
  21. }
  22.  
  23. // Will throw TypeError: const 'x' has already been declared
  24.  
  25. const x = "SECRET"
  26.  
  27. /* complex code */
  28.  
  29. var x = 0
  30.  
  31. // Will reassign y and cause trouble
  32.  
  33. var y = "SECRET"
  34.  
  35. /* complex code */
  36.  
  37. var y = 0
  38.  
  39. const pi = 3.1415926535
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement