NodeJS Common Definitions

First-class functions:

Everything you can do with other types, you can do with functions.

You can use functions like strings, numbers, etc.(i.e. pass them around, set variables equal to them, put them in arrays, and more)

function greet() {
  console.log('hi from greet()');
}

//function are first-class

function logGreeting(fn) {
  fn();
}

// first-class
logGreeting(greet);

var greetMe = function() {
  console.log('hi from greetMe()');
}
// first-class
logGreeting(greetMe);

//
//function expression on the fly
logGreeting(function(){
  console.log('function expression on the fly')
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s