SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
JavaScript
1. JavaScript परिचय 2. JavaScript कहाँ लिखें 3. JavaScript आउटपुट 4. JavaScript सिंटैक्स 5. JavaScript कमेंट्स 6. JavaScript वेरिएबल्स 7. JavaScript ऑपरेटर्स 8. JavaScript डेटा टाइप्स 9. JavaScript फंक्शन्स 10. JavaScript ऑब्जेक्ट्स 11. JavaScript स्कोप 12. JavaScript इवेंट्स 13. JavaScript स्ट्रिंग्स 14. JavaScript नंबर्स 15. JavaScript ऐरे 16. JavaScript ऐरे मेथड्स 17. JavaScript तारीखें 18. JavaScript मैथ 19. JavaScript कंडीशन्स 20. JavaScript स्विच 21. JavaScript For Loop — गिनती वाला लूप 22. JavaScript While Loop — जब तक वाला लूप 23. JavaScript Type Conversion — एक type से दूसरा type 24. JavaScript Errors — try, catch, finally से error पकड़िए 25. JavaScript JSON — डेटा भेजने का तरीका 26. JavaScript Arrow Functions — छोटा रूप, बड़ा फर्क 27. JavaScript Classes — एक बार लिखिए, बार-बार बनाइए 28. JavaScript Promises और async/await — इंतज़ार का तरीका 29. JavaScript और DOM — पेज को पेड़ समझिए 30. JavaScript Form Validation — दरवाज़े पर जाँच
अंतिम टेस्ट — सर्टिफिकेट ₹10
इस कोड को लाइव चलाएँ
पाठ 5, कुल 30 में

JavaScript कमेंट्स

4 मिनट पढ़ें · मुफ़्त · बिना लॉगिन

Comment एक note है जो आप अपने code के अंदर इंसानों के लिए लिखते हैं। Browser इसे पूरी तरह नज़रअंदाज़ कर देता है — यह कभी चलता नहीं, पेज पर कभी दिखता नहीं, और नतीजे पर कभी असर नहीं डालता। Comments सिर्फ एक वजह से होते हैं: ताकि code पढ़ने वाला व्यक्ति बाद में — अक्सर तीन महीने बाद आप खुद — समझ सके कि code क्या कर रहा है और क्यों।

Diagram — देखें, यह सब कैसे जुड़ता है
Diagram: JavaScript कमेंट्स

JavaScript में comments दो तरह के होते हैं। Single-line comment दो slashes // से शुरू होता है और line के अंत तक चलता है। Multi-line comment /* से शुरू होता है और */ पर खत्म होता है, और जितनी lines चाहें उतनी cover कर सकता है। दोनों को browser नज़रअंदाज़ कर देता है।

एक line वाले comments

// का इस्तेमाल एक line के छोटे note के लिए कीजिए — कोई variable क्या रखता है, कोई नंबर वही क्यों है, या अगली line क्या करती है। आप इसे अपनी अलग line पर लिख सकते हैं, या code की line के अंत में।

// Price of one cup of Masala Chai
let price = 10;
let total = price * 3; // 3 cups = ₹30

पहला comment एक value समझाता है। दूसरा comment, line के अंत में, गणित दिखाता है। दोनों visitor को दिखाई नहीं देते।

कई lines वाले comments

/* ... */ का इस्तेमाल तब कीजिए जब note को एक से ज़्यादा lines चाहिए — जैसे file के ऊपर एक छोटा विवरण, या किसी मुश्किल logic की व्याख्या। /* और */ के बीच जो कुछ भी है, वह नज़रअंदाज़ कर दिया जाता है, चाहे वह दस lines में ही क्यों न हो।

/*
  This function calculates the bill for a chai order.
  It adds a 5% tax and gives a 10% discount on orders above ₹100.
*/
function calculateBill(cups, price) {
  let total = cups * price;
  return total;
}
Note: शुरुआती लोगों की एक आम गलती है closing */ भूल जाना। अगर आप multi-line comment खोलते हैं और कभी बंद नहीं करते, तो browser उसके बाद की हर चीज़ को comment मान लेता है — आपका असली code भी — और program चुपचाप कुछ भी नहीं करता।
Tip: Comments अपने code को test करने का भी तेज़ तरीका हैं। अगर कोई line error दे रही है और आपको समझ नहीं आ रहा क्यों, तो उसे // से comment बना दीजिए और पेज फिर से चलाइए। अगर error चला जाए, तो वही line समस्या थी। इस तरकीब को "commenting out" कहते हैं, और पेशेवर लोग इसे हर दिन इस्तेमाल करते हैं।

अच्छा comment कैसा होता है

अच्छा comment क्यों समझाता है, क्या नहीं। Code पहले से दिखाता है कि क्या हो रहा है — let total = cups * price; साफ़ है। जो साफ़ नहीं है, वह यह है कि कीमत 10 क्यों है, या discount सिर्फ ₹100 से ऊपर ही क्यों मिलता है। वजह लिखिए, दोहराव नहीं। और comments छोटे रखिए: अगर comment उस code से लंबा है जिसे वह समझाता है, तो शायद code को दोबारा लिखने की ज़रूरत है, ज़्यादा comments की नहीं।

आम गलतियाँ

  • Multi-line comment का closing */ भूल जाना — उसके बाद की हर चीज़ comment बन जाती है, और code काम करना बंद कर देता है।
  • ऐसे comments लिखना जो code को दोहराते हैं — count = count + 1; के ऊपर // add 1 to count कुछ नहीं जोड़ता। क्यों बताइए, बजाय इसके।
  • Code बदलने के बाद पुराने, गलत comments छोड़ देना — झूठा comment बिना comment के भी बुरा है।
  • Code को comment करके भूल जाना — उसे comment में छोड़ने के बजाय delete कर दीजिए।

याद रखें

  • // एक line को comment बनाता है; /* ... */ कई lines को comment बनाता है।
  • Browser comments को पूरी तरह नज़रअंदाज़ कर देता है — वे सिर्फ इंसानों के लिए notes हैं।
  • अच्छे comments क्यों समझाते हैं, क्या नहीं।
  • Multi-line comment को हमेशा */ से बंद कीजिए।

उदाहरण समझिए

  • // Price of one cup of Kulhad Chai — उस variable के ऊपर single-line comment जिसका वह वर्णन करता है। यह बताता है कि नंबर 20 का मतलब क्या है।
  • let price = 20; // ₹20 per cup — line के अंत में comment, उस line की value के बारे में एक छोटी बात जोड़ता है।
  • Discount नियम के आसपास /* ... */ — multi-line comment दुकान का नियम समझाता है: ₹100 से ऊपर के orders पर 10% छूट मिलती है। यह नियम business logic है, code logic नहीं, इसलिए इसे note की ज़रूरत है।
  • let total = cups * price; — यहाँ कोई comment ज़रूरी नहीं है। Line अपने आप साफ़ है, और comment सिर्फ उसे दोहराता।
  • // Show the final total on the page — आखिरी line से पहले comment, वह कदम बताता है जहाँ जवाब visitor तक पहुँचता है।

उदाहरण

Example
<!DOCTYPE html>
<html>
<head>
<title>Chai Bill with Comments</title>
<style>
body { background-color: #fff8e1; font-family: Verdana, sans-serif; text-align: center; }
h1 { color: #b45309; }
button { background-color: #e13611; color: white; border: none; padding: 12px 24px; font-size: 16px; cursor: pointer; }
#bill { color: green; font-weight: bold; font-size: 18px; }
</style>
</head>
<body>

<h1>Chai Bill with Discount</h1>
<p>6 cups of Kulhad Chai at ₹20 each. Orders above ₹100 get 10% off.</p>
<button onclick="showBill()">Calculate bill</button>
<p id="bill">Click the button to see the total.</p>

<script>
function showBill() {
  // Price of one cup of Kulhad Chai
  let price = 20; // ₹20 per cup
  let cups = 6;
  let total = cups * price;
  /*
    Shop rule: orders above ₹100 get 10% off.
    6 cups cost ₹120, so the discount applies.
  */
  let discount = total * 0.10;
  let finalTotal = total - discount;
  // Show the final total on the page
  document.getElementById("bill").textContent = "Total after discount: ₹" + finalTotal;
}
</script>

</body>
</html>

परिणाम

परिणाम — ब्राउज़र में यह कैसा दिखता है
परिणाम: JavaScript कमेंट्स

खुद करके देखें — लाइव एडिटर

नीचे दिया गया कोड बदलें और चलाएँ दबाएँ — परिणाम तुरंत दिखेगा। कोई फाइल सहेजनी नहीं है, कोई लॉगिन नहीं चाहिए।

परिणाम

Check yourself — did you get it?

Finished the lesson? Test yourself with 5 quick questions — you get the answer instantly, with the reason for each one.

1. What is a comment in JavaScript?

A comment is a note for humans — the browser ignores it completely. It never runs and never shows on the page.

2. Which marks a single-line comment?

A single-line comment starts with two slashes // and runs to the end of the line.

3. What happens if you open a multi-line comment with /* and forget the closing */?

Without the closing */, the browser treats everything after it as a comment — including your real code — and the program silently does nothing.

4. What makes a good comment?

The code already shows what is happening. A good comment explains why — why the price is 10, or why the discount applies above ₹100.

5. What does 'commenting out' a line mean?

Turn a suspicious line into a comment with // and run the page again. If the error goes away, that line was the problem.

Interview questions — can you answer these?

Read the question first, try to answer it in your own words, then open it to check. These are the questions interviewers actually ask.

1. What is a comment in JavaScript, and what are the two kinds?

A comment is a note inside your code for humans — the browser ignores it completely, so it never runs or shows on the page. A single-line comment starts with // and runs to the end of the line, while a multi-line comment starts with /* and ends with */, and can cover as many lines as you like.

2. What makes a good comment, and what is the most common mistake with multi-line comments?

A good comment explains why, not what — the code already shows what is happening, so write the reason, like why the price is 10 or why the discount only applies above ₹100. The most common mistake is forgetting the closing */: if a multi-line comment is never closed, the browser treats everything after it as a comment, including your real code, and the program silently does nothing.

3. What does "commenting out" mean, and when would you use it?

Commenting out means turning a line of code into a comment with // so the browser skips it, without deleting it. It is a quick way to test: if a line is causing an error and you are not sure why, comment it out and run the page again — if the error goes away, that line was the problem. Professionals use this trick every day, but delete dead code instead of leaving it commented in the file.

Try it yourself — build this

Reading is not enough — now build it yourself. Write the code in the live editor, run it, check the hint if you get stuck, and open the solution only after you have tried.

1. Explain the discount with comments

Create a chai bill page: 6 cups of Kulhad Chai at ₹20 each (₹120 total). Orders above ₹100 get 10% off, so the final total is ₹108. Inside a function showBill(), use BOTH kinds of comments: a single-line comment // above the price line explaining what the number 20 means, a multi-line comment /* ... */ explaining the shop's discount rule (orders above ₹100 get 10% off), and a short single-line comment at the end of the line that calculates the total. The button "Calculate bill" must show "Total after discount: ₹108" in a paragraph with id="bill". Do not forget to close the multi-line comment with */.

Hint: Write // Price of one cup of Kulhad Chai above let price = 20;. Wrap the discount rule in /* ... */ before the discount line. Put // 6 cups cost ₹120, so the discount applies at the end of the let total = cups * price; line. A good comment explains why, not what.
Open the live editor
Show solution
<!DOCTYPE html>
<html>
<head>
<title>Chai Bill with Discount</title>
<style>
body { background-color: #fff8e1; font-family: Verdana, sans-serif; text-align: center; }
h1 { color: #b45309; }
button { background-color: #e13611; color: white; border: none; padding: 12px 24px; font-size: 16px; cursor: pointer; }
#bill { color: green; font-weight: bold; font-size: 18px; }
</style>
</head>
<body>

<h1>Chai Bill with Discount</h1>
<p>6 cups of Kulhad Chai at ₹20 each. Orders above ₹100 get 10% off.</p>
<button onclick="showBill()">Calculate bill</button>
<p id="bill">Click the button to see the total.</p>

<script>
function showBill() {
  // Price of one cup of Kulhad Chai
  let price = 20;
  let cups = 6;
  let total = cups * price; // 6 cups cost ₹120, so the discount applies
  /*
    Shop rule: orders above ₹100 get 10% off.
    6 cups cost ₹120, so the discount applies.
  */
  let discount = total * 0.10;
  let finalTotal = total - discount;
  // Show the final total on the page
  document.getElementById("bill").textContent = "Total after discount: ₹" + finalTotal;
}
</script>

</body>
</html>

खुद क्यों सीखें — AI से पूछने के बजाय?

AI आपके लिए कोड लिख सकता है, लेकिन वह आपके लिए सोच नहीं सकता। जब आप HTML खुद सीखते हैं, तो आपका दिमाग असली कौशल बनाता है: आप समझते हैं कि पेज ऐसा क्यों दिखता है, टूटने पर उसे ठीक कर सकते हैं, और परीक्षा या इंटरव्यू में बिना मदद के जवाब दे सकते हैं। यही कौशल नौकरी दिलाता है — कॉपी किया हुआ जवाब नहीं।

सर्टिफिकेट पाएँ — सिर्फ ₹10

सभी 30 पाठ पूरे करें, टेस्ट पास करें (80%), ₹10 दें और अपना सर्टिफिकेट पाएँ।

टेस्ट दें

देखकर सीखना पसंद है? वीडियो कोर्स में वही विषय एक-एक करके सिखाए जाते हैं।

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Master Python + AI Skills in 30 Days
₹499
View
Summer Industrial Training in MERN Stack 2026
₹3,000
View
Full Stack PHP Development Course 2026
₹3,000
View
Browse all courses
JavaScript — Lessons
1. JavaScript परिचय 2. JavaScript कहाँ लिखें 3. JavaScript आउटपुट 4. JavaScript सिंटैक्स 5. JavaScript कमेंट्स 6. JavaScript वेरिएबल्स 7. JavaScript ऑपरेटर्स 8. JavaScript डेटा टाइप्स 9. JavaScript फंक्शन्स 10. JavaScript ऑब्जेक्ट्स 11. JavaScript स्कोप 12. JavaScript इवेंट्स 13. JavaScript स्ट्रिंग्स 14. JavaScript नंबर्स 15. JavaScript ऐरे 16. JavaScript ऐरे मेथड्स 17. JavaScript तारीखें 18. JavaScript मैथ 19. JavaScript कंडीशन्स 20. JavaScript स्विच 21. JavaScript For Loop — गिनती वाला लूप 22. JavaScript While Loop — जब तक वाला लूप 23. JavaScript Type Conversion — एक type से दूसरा type 24. JavaScript Errors — try, catch, finally से error पकड़िए 25. JavaScript JSON — डेटा भेजने का तरीका 26. JavaScript Arrow Functions — छोटा रूप, बड़ा फर्क 27. JavaScript Classes — एक बार लिखिए, बार-बार बनाइए 28. JavaScript Promises और async/await — इंतज़ार का तरीका 29. JavaScript और DOM — पेज को पेड़ समझिए 30. JavaScript Form Validation — दरवाज़े पर जाँच
अंतिम टेस्ट — सर्टिफिकेट ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🛡️ 7-Day Money-Back Guarantee
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Download karne ke liye login karo. Login ke baad yahi page pe rahoge!

Naya ho? Register karo →