2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

普段はJavaを見ているのですが、最近jsを見る機会が多くなっています。
Javaの要領でざっくりと理解はできるのですが、結局ざっくりなので「jsってそうなの!?」と思うこともしばしばあります。
この記事はそういった「そうなの!?」の覚書です。

引数に関数を入れられる

function hoge(name){
    console.log("こんにちは," + name);
}

function fuga(func){
    func("パン派さん!");
}

fuga(hoge);//出力結果:"こんにちは,パン派さん!"

引数の数は足りていなくてもいい

function hoge(name, isSucceeded){
    console.log("こんにちは," + name + "さん!");
    if(isSucceeded === true){
        console.log("処理に成功しています!")
    } else {
        console.log("処理に失敗しています。");
    }
}

hoge("パン派");//出力結果:"こんにちは,パン派さん!処理に失敗しています。"

※isSucceededはundefinedとして処理される。undefinedはfalse扱いなのでelseに入る。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?