Class

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 205:- Class

 

In JavaScript, a class is a blueprint for creating objects that have the same properties and methods. It defines a set of properties and methods that will be shared by all instances of the class. Classes are used to create objects that have a similar structure and behavior, making it easier to manage code and create reusable code.

In JavaScript, classes were introduced in ECMAScript 6 (ES6) as a new syntax for creating objects. Before ES6, JavaScript used a prototype-based inheritance model to create objects.

To define a class in JavaScript, you use the class keyword followed by the name of the class. You can then define a constructor method, which is called when an object is created from the class, as well as any other methods and properties that the class should have.

Here is an example of a simple class definition in JavaScript:

javascriptCopy code

class Person {  constructor(name, age) {    this.name = name;    this.age = age;  }    sayHello() {    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);  } } let person1 = new Person("John", 30); let person2 = new Person("Jane", 25); person1.sayHello(); // Output: Hello, my name is John and I am 30 years old. person2.sayHello(); // Output: Hello, my name is Jane and I am 25 years old.

In this example, we define a Person class with a constructor that takes two parameters, name and age, and sets them as properties of the class. We also define a sayHello method that logs a message to the console.

We then create two instances of the Person class, person1 and person2, and call the sayHello method on each of them to output a message to the console.

22. Constructors And Prototypes

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support