# क्लास और कंस्ट्रक्टर — जावास्क्रिप्ट

Source: https://www.geekswithgeeks.com/hi/javascript/js-classes

> ऑब्जेक्ट के खाके, class कीवर्ड से बने।

## class और constructor

`new` से ऑब्जेक्ट बनाते ही `constructor` अपने-आप चलता है, और उसकी शुरुआती प्रॉपर्टीज़ सेट करता है।

```js
class Dog {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
  bark() {
    return `${this.name} says Woof!`;
  }
}
const rex = new Dog("Rex", 3);
console.log(rex.bark());
```

## क्लास सिंटैक्स शुगर है

अंदरखाने, JS क्लास अब भी prototype उपयोग करते हैं — `class` उसी prototype-आधारित सिस्टम पर एक साफ़ सिंटैक्स है।

## new कीवर्ड

क्लास कंस्ट्रक्टर से पहले `new` भूलने पर `TypeError` आता है — क्लास को सामान्य फ़ंक्शन की तरह नहीं बुलाया जा सकता।
