Define & Instantiate Classes in JavaScript
JavaScript·2 min read·Jan 1, 2025
In JavaScript, a class is a reusable template for creating standardized objects.
Classes are used to describe the internal data structure of these objects (their properties) and implement their functionalities (their methods).
In this lesson, you will learn how to declare classes, define their properties and methods, and create objects from them.
Define a class
In JavaScript, classes are defined using the class keyword:
class ClassName { // class body}Where:
ClassNameis the user-defined name of the class.{}is the body of the class that contains its fields and methods.
Note: By convention, class names always start with a capital letter and are written in CamelCase.
Instantiate a class
To instantiate a class, which means creating a object from it (i.e. an instance), you can use the new keyword, followed by the name of the class, and a pair of parentheses ():
Unlock the program 🚀
Pay once, own it forever.
€79
30-day money-back guarantee
- 13 modules
- 113 lessons with full-code examples
- 29 projects with commented solutions
- All future lesson and project updates
- Lifetime access
By submitting this form, you agree to the Terms & Conditions and Privacy Policy.