【问题标题】:What will be output of this program in javascript [duplicate]这个程序在javascript中的输出是什么[重复]
【发布时间】:2021-11-12 04:54:35
【问题描述】:

我在一次 JS 面试中被问到这个问题

function display() {
  var a = b = 10;
}
display();
console.log('b', typeof b === 'undefined');
console.log('a', typeof a === 'undefined');

我的答案是:b false a false 但是按照面试官的说法应该是b false a true

我没有完全理解他。正确的解释/答案应该是什么?

【问题讨论】:

    标签: javascript function


    【解决方案1】:

    如果你在函数内部写这样的话,那么答案只会是false false。

    function display() 
    {
    var a = b = 10;
    console.log('b',  b === 'undefined');
    console.log('a',  a === 'undefined');
    }
    display();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2017-09-26
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      相关资源
      最近更新 更多