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

More than 3 years have passed since last update.

コールバック関数

Posted at
.js
// これがコールバック関数
function greeting(name) {
  alert('Hello ' + name);
}

// 2. callbackという仮引数名でgreeting関数を受け取る
function processUserInput(callback) {
  
  // 3. 入力フォームを表示させ、入力値を変数に代入
  let name = prompt('Please enter your name.');

  // 4. 3の変数を引数に渡してコールバック関数実行
  callback(name);
}

// 1. greeting関数を引数で渡す
processUserInput(greeting);
1
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
1
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?