相关疑难解决方法(0)

为什么返回类型相同但结果不同

我在java脚本中有两个相同返回类型的函数但返回类型不同.下面使用snipped id的代码

function foo1()
    {
      return {
          bar: "hello"
      };
    }

    function foo2()
    {
      return
      {
          bar: "hello"
      };
    }
Run Code Online (Sandbox Code Playgroud)

调用函数..

console.log("foo1 returns:");
console.log(foo1());
console.log("foo2 returns:");
console.log(foo2());
Run Code Online (Sandbox Code Playgroud)

输出结果....

foo1 returns:
Object {bar: "hello"}
foo2 returns:
undefined 
Run Code Online (Sandbox Code Playgroud)

javascript console console.log

5
推荐指数
2
解决办法
933
查看次数

标签 统计

console ×1

console.log ×1

javascript ×1