LoginSignup
0
1

More than 1 year has passed since last update.

高階関数とコールバック関数の違い

Posted at

はじめに

高階関数とコールバック関数の違いについて整理したいと思います。

定義

高階関数:他の関数を引数として受け取る関数
コールバック関数:高階関数に引数として渡される関数

具体例

main.js

const calc = (x,y) => {
  return x + y;
}

const sum = (x,y,calc) => {
  const total = calc(x, y)
  console.log(`合計値は${total}です`);
  // 合計値は30です
}

sum(10,20,calc)

上記の定義と照らし合わせると、sum関数はcalc関数を引数として受け取る関数なので高階関数となり、calc関数は高階関数であるsum関数に引数として渡されているのでコールバック関数となります。

さいごに

何か間違いなどがあればご指摘していただけるとありがたいです。

参考

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