Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Classes | Classes & Objects
Object-Oriented Programming in JavaScript
course content

Course Content

Object-Oriented Programming in JavaScript

Object-Oriented Programming in JavaScript

1. Classes & Objects
2. Encapsulation
3. Static
4. Inheritance

book
Classes

Hi there! Let's start learning OOP with the JavaScript programming language. Hope you are familiar with JavaScript syntax and can write simple programs. The next step is understanding OOP or Object Oriented Programming. OOP is a programming paradigm with the idea of a specific program organization. It is about creating objects that contain some data and methods. Each object is an instance of some class.

Class definition

You already know about primitive data types like string, number, bool, null, undefined, symbol. In JavaScript, you also can create user-defined data types - the classes. Class is a way how the user can define and represent some data and the behavior for this data.

Let's start with a simple class Circle with no data for now:

123
class Circle { // body of the class }
copy

This class has only a name now. Later, it will contain and describe some data about the circles and can be used, for example, for some geometry application.

For simplicity and clarity, in this course we will follow this way of creating a class, but let's take a look at a bit different ways.

JavaScript feature

There are some other ways to define a class in JS. We can define a class and create some objects at the same time, like this:

1
const firstCircle = class Circle {/* body of the class*/ };
copy

Or define object secondCircle of the class without name, like this:

1
const secondCircle = class{/* body of the class*/ };
copy
Task
test

Swipe to show code editor

Create empty class with name Rectangle.

Since each class represents some specific independent data type, it should contain attributes and methods. Let's go to the next chapter.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 1
toggle bottom row

book
Classes

Hi there! Let's start learning OOP with the JavaScript programming language. Hope you are familiar with JavaScript syntax and can write simple programs. The next step is understanding OOP or Object Oriented Programming. OOP is a programming paradigm with the idea of a specific program organization. It is about creating objects that contain some data and methods. Each object is an instance of some class.

Class definition

You already know about primitive data types like string, number, bool, null, undefined, symbol. In JavaScript, you also can create user-defined data types - the classes. Class is a way how the user can define and represent some data and the behavior for this data.

Let's start with a simple class Circle with no data for now:

123
class Circle { // body of the class }
copy

This class has only a name now. Later, it will contain and describe some data about the circles and can be used, for example, for some geometry application.

For simplicity and clarity, in this course we will follow this way of creating a class, but let's take a look at a bit different ways.

JavaScript feature

There are some other ways to define a class in JS. We can define a class and create some objects at the same time, like this:

1
const firstCircle = class Circle {/* body of the class*/ };
copy

Or define object secondCircle of the class without name, like this:

1
const secondCircle = class{/* body of the class*/ };
copy
Task
test

Swipe to show code editor

Create empty class with name Rectangle.

Since each class represents some specific independent data type, it should contain attributes and methods. Let's go to the next chapter.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 1
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt