7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ECMAScript 仕様の重箱の隅をつつく 1

Posted at

仕様書を読んで見つけた、変な仕様を紹介していくコーナーです。
せっかくなのでクイズ形式で。

今回は関数の再帰呼び出しに関する仕様です。

問題

以下のコードでは、最後の console.log でなんと出力されるでしょうか?

// 1回だけ再帰的に foo を呼び出し、"foo"を返す。
function foo(check) {
    if (check) return "foo";
    else return foo(true);
}

// 1回だけ再帰的に bar を呼び出し、"bar"を返す。
var bar = function bar(check) {
    if (check) return "bar";
    else return bar(true);
};

// 上書きする
var hoge = foo;
var fuga = bar;
foo = bar = function() { return "none"; };

console.log(hoge(), fuga()); // ???

選択肢

  1. foo bar
  2. foo none
  3. none bar
  4. none none

ヒント: http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-runtime-semantics-evaluation

答えと解説

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?