Created
August 6, 2020 08:05
-
-
Save kuredev/86108045b1ca51f26ee5479ee4d739ab to your computer and use it in GitHub Desktop.
【JavaScript】アロー関数とか即時関数とかの書き方メモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1番単純な書き方 | |
function add1(num){ | |
return num + 1 | |
}; | |
console.log(add1(1)); // 2 | |
// 関数リテラルにする | |
add2 = function(num){ | |
return num + 1 | |
}; | |
console.log(add2(1)); // 2 | |
// 関数リテラルにする(アロー関数) | |
add3 = (num) => { | |
return num + 1 | |
} | |
console.log(add3(1)); // 2 | |
// 即時関数 | |
console.log((function(num){ | |
return num + 1; | |
}(1))); // 2 | |
// 関数リテラル(アロー関数)+即時関数 | |
console.log(((num) => { | |
return num + 1; | |
})(1)); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment