开发者社区> 问答> 正文

输出结果是多少?

1

var a; // undefined
var b = a * 0; // NaN
if (b == b) {
  // false
  console.log(b * 2 + "2" - 0 + 4);
} else {
  console.log(!b * 2 + "2" - 0 + 4); // 22 + 4 = 26
}

2

<script>
    var a = 1;
</script>
<script>
var a;
var b = a * 0;
if (b == b) { // true
       console.log(b * 2 + "2" - 0 + 4); // 6
} else {
       console.log(!b * 2 + "2" - 0 + 4);
}
</script>

3

var t = 10;
function test(t) {
var t = t++;
}
test(t);
console.log(t); // 外部不能访问函数内的变量

4


var t = 10;
function test(test) {
  var t = test++;
}
test(t);
console.log(t);

6)

var t = 10; function test(test) { t = test++; console.log(t); } test(t); console.log(t);

答案:10

7)

var t = 10; function test(test) { t = t + test; console.log(t); var t = 3; } test(t); console.log(t);

答案:NaN 10

8)

var a; var b = a / 0; if (b == b) { console.log(b * 2 + "2" - 0 + 4); } else { console.log(!b * 2 + "2" - 0 + 4); }

答案:26

9)

展开
收起
kun坤 2019-11-28 14:45:30 437 0
1 条回答
写回答
取消 提交回答
  • 1)
    
    var a; // undefined
    var b = a * 0; // NaN
    if (b == b) {
      // false
      console.log(b * 2 + "2" - 0 + 4);
    } else {
      console.log(!b * 2 + "2" - 0 + 4); // 22 + 4 = 26
    }
    
    答案:26
    
    2)
    
    <script>
        var a = 1;
    </script>
    <script>
    var a;
    var b = a * 0;
    if (b == b) { // true
           console.log(b * 2 + "2" - 0 + 4); // 6
    } else {
           console.log(!b * 2 + "2" - 0 + 4);
    }
    </script>
    
    答案:6
    
    3)
    
    var t = 10;
    function test(t) {
      var t = t++;
    }
    test(t);
    console.log(t); // 外部不能访问函数内的变量
    
    答案:10
    
    4)
    
    var t = 10;
    function test(test) {
      var t = test++;
    }
    test(t);
    console.log(t);
    
    答案:10
    
    6)
    
    var t = 10;
    function test(test) {
      t = test++;
      console.log(t);
    }
    test(t);
    console.log(t);
    
    答案:10
    
    7)
    
    var t = 10;
    function test(test) {
      t = t + test;
      console.log(t);
      var t = 3;
    }
    test(t);
    console.log(t);
    
    答案:NaN 10
    
    8)
    
    var a;
    var b = a / 0;
    if (b == b) {
      console.log(b * 2 + "2" - 0 + 4);
    } else {
      console.log(!b * 2 + "2" - 0 + 4);
    }
    
    答案:26
    
    9)
    
    <script>
         var a = 1;
    </script>
    <script>
       var a;
       var b = a / 0;
       if (b == b) {
           console.log(b * 2 + "2" + 4);
       } else {
           console.log(!b * 2 + "2" + 4);
       }
    </script>
    
    答案:Infinity24
    
    
    2019-11-28 14:45:43
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载