习题讲解_练习题1.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 第一题
  11. // var n = 13;
  12. // function fn(n) {
  13. // alert(n);//13
  14. // n = 14;
  15. // alert(n);//14
  16. // }
  17. // fn(n);
  18. // alert(n)//13
  19. // 第二题
  20. // var n = 0;
  21. // function a() {
  22. // var n = 10;
  23. // function b() {
  24. // n++;
  25. // alert(n);//11
  26. // }
  27. // b();
  28. // }
  29. // a();
  30. // alert(n);//0
  31. // 第三题
  32. // console.log(num, str);//undefined undefined
  33. // var num = 18;
  34. // var str = "lily";
  35. // function fn2() {
  36. // console.log(str, num);// lily undefined
  37. // num = 19;
  38. // str = "candy";
  39. // var num = 14;
  40. // console.log(str, num);// candy 14
  41. // }
  42. // fn2();
  43. // console.log(str, num);// candy 18
  44. // 第四题
  45. // fn();//2
  46. // function fn() { console.log(1) };
  47. // fn();//2
  48. // var fn = 13;
  49. // // fn();//fn is not a function
  50. // function fn() { console.log(2) };
  51. // // fn();fn is not a function
  52. // 第五题
  53. // (function f() {
  54. // function f() { console.log(1) };
  55. // f();//2
  56. // function f() { console.log(2) };
  57. // })();
  58. // 第六题
  59. // if (!("a" in window)) {
  60. // var a = 10;
  61. // }
  62. // alert(a);//undefined
  63. // console.log(fn);//undefined
  64. // if (9 == 8) {
  65. // function fn() {
  66. // alert(2);
  67. // }
  68. // }
  69. // in 运算符 判断对象是否有某个属性
  70. // var ojb = {
  71. // a:1,
  72. // b:2,
  73. // c:3
  74. // }
  75. // console.log("d" in ojb);
  76. // 第七题
  77. // function fn() {
  78. // var i = 5;
  79. // return function (n) {
  80. // console.log(n * i++);
  81. // }
  82. // }
  83. // var f = fn();
  84. // f(4);//20
  85. // fn()(5);//25
  86. // f(6);//36
  87. // function foo(){
  88. // var a = 1;
  89. // console.log(a);
  90. // }
  91. // // 函数每次调用都会生成一个新的作用域
  92. // foo();
  93. // foo();
  94. </script>
  95. </body>
  96. </html>