© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
J. SimpsonHow JavaScript Works https://doi.org/10.1007/978-1-4842-9738-4_6

6. Functions and Classes

Jonathon Simpson1  
(1)
Belfast, Antrim, UK
 

Functions and classes are what we use to wrap certain pieces of functionality into reusable blocks. By using a function or class, we can repeat specific tasks many times without having to rewrite the code. When JavaScript was originally released, it only had functions and used prototypes for inheritance. We covered this type of inheritance when we looked at objects.

Classes came later to JavaScript, but they are largely just syntactic sugar for prototype-based inheritance. As such, many developers in JavaScript choose ...

Get How JavaScript Works: Master the Basics of JavaScript and Modern Web App Development 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.