Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Class Attributes | Classes & Objects
Object-Oriented Programming in JavaScript
Section 1. Chapter 2
single

single

bookClass Attributes

Swipe to show menu

Attributes are some variables inside the class that describe each object. Let’s demonstrate it with two classes – Rectangle and Student.

We can represent Rectangle by its height and width. Add these Attributes to the class definition:

1234
class Rectangle{ height; width; }
copy

If you need to describe student in some way, you can create class Student with attributes like, for example, name and university.

1234
class Student{ name; university; }
copy
Task

Swipe to start coding

Add more attributes to the class Student: age and gpa variables.

Solution

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 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt