JavaScript -A Lamda Function

GitHubCodeCommit

The next method is not an actual method or an operator, but a style of writing a function.  In the past, I would usually write something like this:

function myFunction() {

//do something here

}

However, like other languages, JavaScript allows you to write one line methods called Lambda’s.  This is useful for chaining .then() clauses to asynchronous code involving callbacks and/or Promises.  In the sample below, I write a Lambda method logging the contents of each array element:

array.forEach((arrayElement => console.log(arrayElement));

myComplexObjectArray.forEach((arrayElement) => console.log(JSON.stringify(arrayElement)));

screen-shot-2017-02-21-at-8-41-38-pm

Stay tuned!

Advertisements

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