YUNOVA · JavaScript
Module 13: Classes Aur Modules
JavaScript mein class aur constructor kaise banayein
Key points
- class objects बनाने का खाका है; new लगाकर उससे object बनता है।
- constructor new लगाते ही चलता है और this पर शुरुआती values रखता है।
- class के अंदर लिखे methods सब objects साझा करते हैं।
JavaScript class mein inheritance kaise karein
Key points
- extends से एक class दूसरी class की properties और methods ले लेती है।
- child class के constructor में this से पहले super() call करना ज़रूरी है।
- child उसी नाम का method फिर लिखकर parent वाला बदल सकती है; इसे override कहते हैं।
JavaScript mein import aur export kaise karein
Key points
- export किसी file की चीज़ दूसरी files के लिए खोलता है और import उसे लाता है।
- named export {} में नाम से आता है; default export एक file में एक ही होता है।
- browser में module के लिए <script type="module"> लिखना पड़ता है।
JavaScript mein optional chaining aur nullish coalescing kya hai
Key points
- optional chaining ?. रास्ते में null या undefined मिले तो error की जगह undefined देता है।
- nullish coalescing ?? सिर्फ़ null या undefined पर default value देता है।
- || 0 और "" पर भी default दे देता है, ?? नहीं देता; यही दोनों का फ़र्क है।