Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. console.log(typeof name); // undefined
  2. var name = "John";
  3.  
  4. console.log(typeof name); // ReferenceError
  5. let name = "John";
  6.  
  7. console.log(typeof name); // ReferenceError
  8. const name = "John";
  9.  
  10. x = "global";
  11. // function scope:
  12. (function() {
  13. x; // not "global"
  14.  
  15. var/let/… x;
  16. }());
  17. // block scope (not for `var`s):
  18. {
  19. x; // not "global"
  20.  
  21. let/const/… x;
  22. }
  23.  
  24. x = y = "global";
  25. (function() {
  26. x; // undefined
  27. y; // Reference error: y is not defined
  28.  
  29. var x = "local";
  30. let y = "local";
  31. }());
  32.  
  33. function doSomething(arr){
  34. //i is known here but undefined
  35. //j is not known here
  36.  
  37. console.log(i);
  38. console.log(j);
  39.  
  40. for(var i=0; i<arr.length; i++){
  41. //i is known here
  42. }
  43.  
  44. //i is known here
  45. //j is not known here
  46.  
  47. console.log(i);
  48. console.log(j);
  49.  
  50. for(let j=0; j<arr.length; j++){
  51. //j is known here
  52. }
  53.  
  54. //i is known here
  55. //j is not known here
  56.  
  57. console.log(i);
  58. console.log(j);
  59. }
  60.  
  61. doSomething(["Thalaivar", "Vinoth", "Kabali", "Dinesh"]);
  62.  
  63. for(var i=0; i<5; i++){
  64. setTimeout(function(){
  65. console.log(i);
  66. },1000)
  67. }
  68.  
  69. for(let i=0; i<5; i++){
  70. setTimeout(function(){
  71. console.log(i);
  72. },1000)
  73. }
  74.  
  75. const foo = {};
  76. foo.bar = 42;
  77. console.log(foo.bar); //works
  78.  
  79. const name = []
  80. name.push("Vinoth");
  81. console.log(name); //works
  82.  
  83. const age = 100;
  84. age = 20; //Throws Uncaught TypeError: Assignment to constant variable.
  85.  
  86. console.log(age);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement