What are Comments in Code?

Comments in code are unexecuted lines of code that are not run by the computer, and can be used to add additional information or guidance within the code. You can use comments to explain a complex algorithm, add reminders of things to do later, or just explain code for documentation. This would be like the computer reading a recipe you wrote but you’ve told them to ignore certain lines of the recipe.

Dependent on the programming language, comments are usually prefixed or wrapped in certain syntax to ensure the computer knows that they’re comments and are not to be executed.

The below code has three lines, the first line is a comment and will not be executed. The language used is JavaScript and in this language to write single line comments we prefix the line with two forward slashes ‘/’. The next two lines will be executed, as with normal code.

Leave a Reply