Comments in React — React Technical Interview Questions & Answers

Comments in React

Comments in React

  • Inside JSX you cannot use <!-- HTML comments -->. Use {/* comment */}. Outside JSX, normal // and /* */. That’s the whole topic. People hit this when they paste HTML into a component.
  • Comments in React — <!-- HTML comments --> don’t work inside JSX. Use {/* */}.

Technical Interview Tip: {/* */} in JSX.

Code Examples for Comments in React

Example

// JSX comment
export default function Page() {
  return (
    <main>
      {/* promo banner off for exams */}
      <h1>Prep</h1>
    </main>
  );
}

Comments in React — <!-- HTML comments --> don’t work inside JSX. Use {/* */}.

How to Explain Comments in React to an Interviewer

Explain Comments as if you are teaching a junior — definition, then one tiny UI.

JSX : {/* */}. JS : // or /* */.

Write 5–10 lines that use Comments and say what the UI does.

Show JSX Say the screen

What mistake do freshers make with Comments?

<!-- --> inside JSX.