JavaScript Comments
A good developer writes code that a machine can understand. A senior developer writes code that other humans can understand. Comments are the bridge.
Single-Line Comments
Created using two forward slashes //. Anything following these slashes on that specific line is entirely ignored by the JavaScript compiler. They are perfect for brief explanations of complex logic or marking variables.
Multi-Line Comments (Block Comments)
Created using /* to open and */ to close. They are used for long, detailed documentation or to temporarily disable a large block of code during debugging.
Commenting for Debugging
Often, you'll encounter a bug that crashes your application. Instead of deleting lines to test what's broken, you "comment them out." This prevents execution, allowing you to isolate the error without losing your work.
View Full Best Practices+
1. Don't state the obvious: `let age = 10; // Sets age to 10` is bad practice. Only comment *why*, not *what*.
2. Keep them updated: A comment that contradicts the code is worse than no comment.
3. Use JSDoc for APIs: For functions shared across teams, use `/** ... */` syntax to document parameters and return types.
