Home | Mailing List | Blog | Tutorial Videos

Callback setTimeOut

Which of the following functions will add two variables and pass the sum to a callback function after 2 seconds?

// A
const add = (x, y, callback) => {
  setTimeout(() => {
    callback(x + y)
  }, 2);
}

// B
const add = (x, y, callback) => {
  setTimeout(() => {
    callback(x + y)
  }, 2000);
}

// C
const add = (x, y, callback) => {
  setTimeout(() => {
    callback(x + y, 2)
  });
}


// D
const add = (x, y, callback) => {
  setTimeout(() => {
    callback(x + y, 2000)
  });
}

Select one: