As you write more code and start to share your code with others, it is important to add comments into your code to make your intentions known and for future references. The comments become part of your program. However, their main function is to provide additional information to you and readers of your program. They do not trigger any actions in the program. This can be helpful if you want to disable certain codes for testing purposes or to remove them from the program execution altogether.
You can write comments in a single line or with multiple lines of text. To create a single line of comment, you just need to add // in front of the line of text you want to comment out, like this:
// This is a comment. Anything included in this line will not be executed.
If you want to comment out multiple lines of text or code, you can start by using /* and end your comment with */. Anything in betwwen will be commented out, i.e., will not be executed – see an example below.
/* Anything included in this line and the next line will not be executed. This lin ewill be ignore since it is part of the comment */
As an exercise, try to add a comment in your program. Now try to commented out a functional line by placing // in front of the function, and click the play button to see the effect.
What did you learn from this lesson? What did you try? What are your takeaways. Please leave your comments below. We’d love to hear from you.