Comments in programming languages are used to document the programs. Comments are non-executable and are used to explain the code written in the program. Different programming languages have different syntax for writing the comments in the program. Let’s have a look at a few of them.



Table 1: Languages and Comment Syntax Examples

Language Comment Syntax
HTML <!-- comment -->
XML <!-- comment -->
CSS /* comment */
JavaScript // single-line
/* multi-line */
TypeScript // single-line
/* multi-line */
Java // single-line
/* multi-line */
/** doc */
PHP // single-line
# single-line
/* multi-line */
SQL -- single-line
/* multi-line */
# (MySQL)
Python # single-line
Ruby # single-line
=begin / =end
Elixir # single-line
R # single-line
Kotlin // single-line
/* multi-line */
Scala // single-line
/* multi-line */
Rust // single-line
/* multi-line */
/// doc
C // single-line
/* multi-line */
C++ // single-line
/* multi-line */
C# // single-line
/* multi-line */
/// doc
Go // single-line
/* multi-line */
Swift // single-line
/* nested multi-line */
Bash / Shell # single-line



Table 2: Comment Syntax Examples and Languages

Comment Syntax Languages
<!-- --> HTML, XML
/* */ CSS, JavaScript, TypeScript, Java, PHP, SQL, Kotlin, Scala, Rust, C, C++, C#, Go, Swift
// JavaScript, TypeScript, Java, Kotlin, Scala, Rust, C, C++, C#, Go, Swift
# Python, Ruby, Elixir, R, PHP, Bash, SQL (MySQL)
-- SQL
=begin / =end Ruby
/** */ Java, PHP, JavaScript (Doc comments)
/// Rust, C#