- In programming, comments can also be used to prevent some code lines from being executed. This is useful when testing.
- There are single-line comments (which comment out one line or a part of one line) and multi-line comments (which comment out a block of code).
- Multi-line comments are more often used for formal documentations.
Comment vs. Comment Out
Check out the example of commenting out a single-line below:
//document.getElementById("test_el").innerHTML = "Some text"; document.getElementById("test_el2").innerHTML = "Some more text";
This example illustrates the commenting out a block of code:
/* document.getElementById("test_el").innerHTML = "some text"; document.getElementById("test_el2").innerHTML = "some more text"; */
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
The example below uses a single-line comment to explain a line of code below the comment:
In the example below, a comment is written on the same line as the code itself:
var x = 5; // Variable declaration var y = x + 99; // Different variable
For a single-line comment, you have to write two forward slashes:
//. Anything that goes after
/*. To end the comment, use these symbols
- Comments can be used to explain or hide the code so it is not executed.