Parameters of passed functions in JavaScript

Suppose we have the function test that takes another function as a parameter and print the result of this passed function to the console:

javascriptfunction test(func) {
  console.log( func() );
}

Let the passed function func take a number as a parameter and do something with it. Let's give it, for example, the number 3:

javascriptfunction test(func) {
  console.log( func(3) );
}

Let's now call the test function, passing an anonymous function as a parameter to it. This anonymous function will take a number as a parameter and return the square of that number.

As a result of all this, our construction will display the square of the number 3, that is, 9:

javascript// Shows 9:
test(
  function(num) {
    return num * num;
  }
);

function test(func) {
  console.log(func(3));
}

Let's make the code more elegant:

javascript// Shows 9:
test(function(num) {
  return num * num;
});

function test(func) {
  console.log(func(3));
}
Задание 1

Copy my function test code. Invoke this function, passing to it an anonymous function as a parameter, which will take a number as a parameter and return its cube.

Задание 2

Modify your code so that the passed function is not anonymous, but is defined as a Function Declaration with the name func.

Задание 3

Change the passed function to a Function Expression with the same name func.

Задание 4

Let the passed function now take two parameters and return their sum. When calling the passed function inside test, pass the number 2 and the number 3 to the passed function. Print the result.