LoginSignup
1
2

More than 5 years have passed since last update.

JavaScriptでデフォルト引数

Posted at

jsでデフォルト引数使いたい時

yasyoku.js
;(function(){

    // 夜食食べる
    var eatMidnightMeal = function(aMeal){
        aMeal = aMeal || 'ラーメン';
        console.log(aMeal + '食べる');
    };

    eatMidnightMeal(); // ラーメン食べる
    eatMidnightMeal('ポテチ'); // ポテチ食べる

    /*
    aMeal = aMeal || 'ラーメン';

    aMealが存在したらaMeal、 
    なかったらラーメンが代入される。
    */
})();

以上。

1
2
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
1
2