...

/

From Anonymous to Arrow Functions

From Anonymous to Arrow Functions

Learn the different ways to define and use functions in JavaScript and understand how writing functions in JavaScript have evolved.

Anonymous functions have been in JavaScript from day one. Now, newer arrow functions, reduce clutter and make the code more expressive. At first sight, arrow functions may appear to be a direct replacement for anonymous functions, but significant semantic differences exist between them. Learning these differences is critical to avoid surprises when you’re refactoring code to use arrow functions.

Three ways to define JavaScript functions

In JavaScript, there are three different ways to define a function.

Regular functions

A named function uses the function keyword followed by the name of the function.

For example, the following code defines a function named sqr:

function sqr(n) { return n * n; }

Anonymous functions

An anonymous function has the ...

Access this course and 1400+ top-rated courses and projects.