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 was responsible for popularizing their usage. However, the lambda syntax in JavaScript has not been very concise. ES6 arrow functions fill that gap and provide a concise syntax to write functions.
Arrow function...