JS MASTER CLASS /// DOCUMENT YOUR CODE /// AVOID BUGS /// COMMENTING OUT /// JS MASTER CLASS /// DOCUMENT YOUR CODE /// AVOID BUGS /// COMMENTING OUT ///

JavaScript Comments

Learn how to communicate with other humans inside your codebase and debug effectively.

script.js
1 / 11
1234567
💬

Tutor:Code isn't just for computers. It's for humans too. JavaScript comments allow you to leave notes in your code that the browser will completely ignore.


Skill Matrix

UNLOCK NODES BY MASTERING JS COMMENTS.

Concept: Single-Line

Everything after // on the same line is ignored.

System Check

What characters initialize a single-line comment?


Community Holo-Net

Share Your Best Debug Stories

ACTIVE

Ever solved a massive bug just by commenting out lines until it worked? Share your pain and triumphs.

JavaScript Comments

Author

Pascual Vila

Senior Developer // Code Syllabus

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.

JS Comments Glossary

Single-Line Comment

A comment that only spans one line, beginning with //.

snippet.js

Multi-Line Comment

A comment spanning multiple lines, bounded by /* and */.

snippet.js

Commenting Out

The practice of turning executable code into a comment to temporarily prevent it from running during debugging.

snippet.js

JSDoc

A popular standard for writing API documentation in JavaScript comments, usually starting with /**.

snippet.js

Compiler / Engine

The program running in the browser (like V8) that reads JavaScript. It completely ignores all comments.

snippet.js