Comments in JavaScript
Comments are lines in your code that JavaScript ignores when running the program. They are used to explain what the code does, making it easier to understand later – for yourself or for others reading your code.
Good comments improve code readability and help with debugging and collaboration.
Single-Line Comments
Use // for comments on a single line. Everything after // on that line is ignored.
Multi-Line (Block) Comments
Use /* to start and */ to end a comment that can span multiple lines.
When to Use Comments
- Explain complex logic.
- Document functions or variables.
- Temporarily disable code during testing (comment out lines).
- Add notes for future improvements.
Avoid over-commenting obvious code – write clear code instead.
Practical Example
Quick Quiz
Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.
✨ Pregunta a Lara — tu compañera de estudio con IA
Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.
Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.


