Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Javascript で奇妙な動作を見つけました。
function() { return 10; }();
この構文は、構文エラーがあるため、すべてのブラウザーで機能するとは限りません。しかし、この構造は機能します (10 を返します):
+function() { return 10; }();
なんで?
は+、js エンジンがこの関数式と関数定義を区別できるようにします。
+
読みやすくするために、通常は
(function() { return 10; })();
関連記事を見る