Arrow functions

JavaScript uses almost all variations of arrows. With ES6, it introduces a new syntax for writing functions. We have always written function expressions in JavaScript. It is idiomatic to write code like this in JavaScript (this example is in jQuery):

    $("#submit-btn").click(function (event) { 
      validateForm(); 
      submitMessage(); 
    }); 

This is a typical jQuery event handler. The event handler click() function accepts a function as a parameter and we will simply create an inline anonymous function expression and pass it to the click function. This style of writing anonymous function expressions is known as Lambda functions. Several other languages support this feature. Though lambdas are more or less standard in new languages, JavaScript ...

Get Object-Oriented JavaScript - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.