Understanding code with comments

There’s another tool that we also can use to make things easier to understand for a person reading our code—comments.

Indentation and blank lines aren’t always enough to make the intent of the code clear. In these cases, we can use comments. A comment is a line of normal text inserted in the code, which is only for humans and is not compilable. We use them to explain lines of code that are not obviously understood at first glance.

The compiler or interpreter ignores comments, so we need a way to indicate that something is a comment. We have two variants of comments: one that runs to the end of the line, called a line comment, and one that spans multiple lines, often referred to as a block comment. Let’s learn about each of them in more detail.

Get hands-on with 1200+ tech skills courses.