Defining a Method

Dive into the basics of class methods and learn the power and perils of class methods in JavaScript.

Methods are an integral part of classes. They exhibit behavior and are often used to perform some action, or possibly to effect state change.

Syntax

To define a method, place the function body within the {} of the class definition—but without the function keyword.

svg viewer

Example

Let’s rewrite the Car class, this time ...

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