JavaScript · Lesson 05 / 32 · தமிழ்
JavaScript Comments
கருத்தைப் புரிந்துகொள்ளுங்கள். Code-ஐ மாற்றி இயக்குங்கள். ஒரு சிறிய பயிற்சியால் கற்றதை உறுதி செய்யுங்கள்.
மூலப் பாட விளக்கங்கள் தமிழில் உள்ளன. கூடுதல் concept, practice மற்றும் answer notes ஆங்கிலத்தில் உள்ளன.
முக்கியக் கருத்து
Comments explain intent without executing. Use a line comment for a short reason and a block comment when a longer explanation is needed.
Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.
விரிவான விளக்கங்கள்
JavaScript-ல Comments
Comments என்பது JavaScript execute பண்ணாத code lines. அவை code-ஐ மத்த developers-கிட்ட explain பண்ண use ஆகும் — உன்னோட future self-கிட்டயும் கூட!
Single-Line Comments
// இது single-line comment
console.log("Hello"); // line-ன் கடைசியிலயும் வரலாம்
// WHAT-ஐ விட WHY-ஐ explain பண்றது நல்லது
const TAX_RATE = 0.08; // 8% sales tax — state law படி
// Code-ஐ temporarily disable பண்ண
// console.log("debug output");Multi-Line Comments
/*
இது multi-line comment.
பல lines span பண்ணும்.
நீண்ட explanations-க்கு useful.
*/
/*
Code block-ஐ temporarily disable பண்ண:
const result = oldSlowFunction();
process(result);
*/JSDoc Comments
JSDoc என்பது JavaScript-க்கான documentation standard. VS Code மாதிரி IDEs இந்த comments-ஐ படிச்சு inline hints மற்றும் type information காட்டும்.
/**
* Tax சேர்த்து total price calculate பண்ணும்.
* @param {number} price - Base price (dollars-ல)
* @param {number} taxRate - Tax rate as decimal (e.g. 0.08 for 8%)
* @returns {number} Tax சேர்த்த total price
*/
function calculateTotal(price, taxRate) {
return price * (1 + taxRate);
}
// இப்போ VS Code hints காட்டும்:
calculateTotal(100, 0.08); // returns 108நல்ல comments: Code என்ன செய்யுதுன்னு சொல்லாதே — variable/function names அதை already சொல்லும். WHY என்னன்னு சொல்லு. Code-ஐ repeat பண்ற comments noise மட்டுமே.
முழுமையான உதாரணம்
Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.
// Delivery is free for this example.
const subtotal = 300;
/* Keep delivery separate so the rule
can change later. */
const delivery = 0;
console.log(subtotal + delivery);எதிர்பார்க்கும் முடிவைப் பாருங்கள்
300
மாற்றி இயக்கிப் பாருங்கள்
Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.
Editor load ஆனதும் code-ஐ ஏற்றி Run அழுத்துங்கள்.
OneCompiler என்ற இலவச வெளிப்புற சேவை code-ஐ இயக்குகிறது. Run செய்யும் code அங்கு அனுப்பப்படும். தனிப்பட்ட தகவல்கள் அல்லது secret keys உள்ளிட வேண்டாம்.
சிறிய பயிற்சி
Practice challenge
Set delivery to 40 and update the comment to match.
விடை மற்றும் விளக்கம்
The result becomes 340. Comments should describe the rule actually used by the code.
தவிர்க்க வேண்டிய தவறு: A comment cannot repair invalid code outside it. Do not nest block comments.
அடுத்த பாடத்திற்குத் தயாரா?
- Explain the example in your own words.
- Complete the challenge before revealing its answer.
- Describe the common mistake and how to avoid it.