How to Comment in JavaScript, TypeScript, HTML, CSS, and React?

Coding Adventure with Emma
2 min readJust now

--

Comments are essential in programming for documenting code, improving its readability, and providing notes to developers. They help explain complex logic, remind you of decisions made during development, and make it easier to maintain and debug code. Here’s how you can write comments in several popular programming languages: JavaScript, TypeScript, HTML, CSS, and React.

JavaScript and TypeScript Comments

JavaScript and TypeScript share the same syntax for writing comments.

• Single-line:

Use // for single-line comments.

• Multi-line:

Use /* */ for comments spanning multiple lines.

HTML Comments

In HTML, comments are used to annotate the structure or give information that doesn’t appear in the rendered output.

• Syntax:

Use <! — → to create comments that don’t appear in the rendered output.

CSS Comments

Comments in CSS are important for documenting styles and explaining complex rules.

• Syntax:

Use /* */ for CSS comments, just like in JavaScript and TypeScript.

React (JSX) Comments

• JavaScript Comments:

Use JavaScript-style comments (//, /* */) outside JSX.

• JSX Comments:

Use {/* */} within JSX.

--

--

Coding Adventure with Emma

Here you’ll find tutorials, coding challenges, project walkthroughs, and insights into the latest in programming tech.