Recall & Review
beginner
What is a class in JavaScript?A class is a blueprint for creating objects. It defines properties and methods that the created objects will have.Click to reveal answer
beginner
How do you define a class in JavaScript?Use the <code>class</code> keyword followed by the class name and curly braces. Inside, define a <code>constructor</code> method and other methods.Click to reveal answer
beginner
What is the purpose of the
constructor method in a class?The
constructor method runs automatically when you create a new object from the class. It sets up initial values for the object.Click to reveal answer
beginner
How do you create an object from a class?
Use the <code>new</code> keyword followed by the class name and parentheses. For example: <code>const obj = new ClassName();</code>Click to reveal answer
beginner
Can class methods access properties of the object? How?Yes, class methods use <code>this</code> to access the object's properties and other methods.Click to reveal answer
Which keyword is used to define a class in JavaScript?
✗ Incorrect
The
class keyword is used to define a class.What does the
constructor method do?✗ Incorrect
The
constructor method initializes new objects when created.How do you create an object from a class named
Car?✗ Incorrect
Use
new Car(); to create an object from the class.Inside a class method, how do you refer to the current object?
✗ Incorrect
The keyword
this refers to the current object inside class methods.Which of these is NOT true about JavaScript classes?
✗ Incorrect
Classes are special syntax, not regular functions, even though under the hood they use functions.
Explain how to create a class with a constructor and a method in JavaScript.
Think about the basic structure of a class and how you make objects from it.
You got /4 concepts.
Describe the role of the
this keyword inside class methods.Consider how methods know which object's data to use.
You got /4 concepts.