Guest User

Untitled

a guest
Nov 20th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. for(let i = 0; i < 1; i++) {
  2. alert(i);
  3. }
  4. alert(i);
  5.  
  6. for(var i = 0; i < 1; i++) {
  7. alert(i);
  8. }
  9. alert(i);
  10. //# sourceMappingURL=test.js.map
  11.  
  12. "scripts": {
  13. "start": "tsc && concurrently "npm run tsc:w" "npm run lite" ",
  14. "lite": "lite-server",
  15. "postinstall": "typings install",
  16. "tsc": "tsc",
  17. "tsc:w": "tsc -w",
  18. "typings": "typings"
  19. },
  20.  
  21. for(let i = 0; i < 1; i++) {
  22. alert(i);
  23. }
  24. alert(i); // compile error: cannot find name 'i'
  25.  
  26. for (let i = 0; i < 3; i++) {
  27. setTimeout(function() { alert(i); });
  28. }
  29.  
  30. function theDifference(){
  31. for(let emre = 0; emre < 10; emre++){
  32. // emre is only visible inside of this for()
  33. }
  34.  
  35. // emre is NOT visible here.
  36. }
  37.  
  38. function theDifference(){
  39. for(var emre = 0; emre < 10; emre++){
  40. // emre is visible inside of this for()
  41. }
  42.  
  43. // emre is visible here too.
  44. }
  45.  
  46. console.log('not defined = ' + notDefinedIsLegal);
  47. var notDefinedIsLegal;
  48.  
  49. console.log('mustBeDefined = '+ mustBeDefinedBeforeUse);
  50. let mustBeDefinedBeforeUse = 'Hello World';
  51.  
  52. console.log('not defined = ' + notDefinedIsLegal);
  53. var notDefinedIsLegal : string;
  54.  
  55. let mustBeDefinedBeforeUse = 'Hello World';
  56. console.log('mustBeDefined = '+ mustBeDefinedBeforeUse);
  57.  
  58. {
  59. var notDefinedIsLegal = "legal!";
  60. let mustBeDefinedBeforeUse = "Goodbye World!!";
  61. console.log('[blockscoped] mustBeDefined = '+ mustBeDefinedBeforeUse);
  62. console.log('[blockscoped] notDefinedIsLegal = ' + notDefinedIsLegal);
  63. }
  64.  
  65. console.log('mustBeDefined = '+ mustBeDefinedBeforeUse);
  66. console.log('notDefinedIsLegal = '+ notDefinedIsLegal);
  67.  
  68. not defined = undefined
  69. mustBeDefined = Hello World
  70. [blockscoped] mustBeDefined = Goodbye World!!
  71. [blockscoped] notDefinedIsLegal = legal!
  72. mustBeDefined = Hello World
  73. notDefinedIsLegal = legal!
Add Comment
Please, Sign In to add comment