JSFiddle - React, Tailwind, and code Playground

by secretgspot

JavaScript

//無名関数
var hello = function () {
  document.write("hello<br />");
};
hello();


//無名関数を定義してすぐに実行
(function(){document.write("test<br />");})();


//関数を返す関数
function hello2() {
  var hello = function (){
    document.write("hello2<br />");
  };
  return hello; //()なし
}
hello2();   //これでは実行されない
hello2()(); //これだと実行される
var h2 = hello2();
h2();       //実行される(一度変数に代入するのが普通?)


function hello3() {
  var hello = function (){
    document.write("hello3<br />");
  };
  return hello(); //()あり
}

var h3_1 = hello3();  //この時点で実行される