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

Functions are like Objects

Last updated at Posted at 2019-12-13

##A function is similar to objects##

  • A function is an instance of the Object type
  • A function can be stored in a variable
  • A function can be passed as an argument to another function

First class function?

##Passing a function as an argument##

var numbers = [1,4,6,1,9]

function arrayCalc(arr,fn){
  var arrRes = [];
  for (var i = 0; i < arr.length; i++){
  arrRes.push(fn(arr[i]));
  }
  return arrRes;
} 

function calculatePower(num){
  return num**2;
}

//Calculate power without brackets since it is a call back function
arrayCalc(years,calculatePower);
0
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
0
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?