Skip to Main Content
Rediscovering JavaScript
book

Rediscovering JavaScript

by Venkat Subramaniam
June 2018
Beginner content levelBeginner
288 pages
6h 31m
English
Pragmatic Bookshelf
Content preview from Rediscovering JavaScript

From Anonymous to Arrow Functions

JavaScript has three different ways to define a function.

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; }

An anonymous function has the same structure, except it does not have a name—it’s anonymous. An anonymous function can be passed to another function as an argument or stored into a variable. For example, here’s an anonymous function that is stored into a variable named sqr:

 const​ sqr = ​function​(n) { ​return​ n * n; };

The third relatively new function form that JavaScript supports is an arrow function. An arrow (=>) separates the parameter list from the short body of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Object-Oriented JavaScript - Third Edition

Object-Oriented JavaScript - Third Edition

Stoyan STEFANOV, Ved Antani
Deno Web Development

Deno Web Development

Alexandre Portela dos Santos

Publisher Resources

ISBN: 9781680506174Errata Page