Parameter receiving parameters

Asked

Viewed 20 times

1

I’m having a hard time understanding this code, so I’m pretty new.. on the given line the above anonymous function parameter is receiving other parameters? parameters can receive parameters? I can’t understand how this code is working

function calculator (num1, num2) {
    return function (callback) {
      return callback(num1, num2); // ESSA LINHA <<<<<<<<<<<<<<<
    };
  }

var sum = calculator(10, 2);

console.log( 'O resultado da soma é:' );
  console.log(sum(function (number1, number2) {
    return number1 + number2;
  }));
  • They can be invoked because they are functions. Yes, you can pass a function as argument to a function! : ) This is called callback. I marked your question as duplicate as it has already been answered here on the site. The above question notice has a link to the question on the subject.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.