Skip to content

Commit f51e10d

Browse files
SamBSalgadosumn2u
authored andcommitted
Apply formatting structure suggested in issue #79
1 parent e1a19ad commit f51e10d

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

en/basics/comments.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,49 @@ description: Comments are used to mark annotations for other programmers or smal
88

99
Comments are statements that will not be executed by the interpreter. They are used to mark annotations for other programmers or small descriptions of what code does, thus making it easier for others to understand what your code does. They are also used to temporarily disable code without affecting the program control flow.
1010

11-
In JavaScript, comments can be written in two different ways:
11+
## Types of Comments
1212

13-
* **Single-line comments**: It starts with two forward slashes (`//`) and continue until the end of the line. Anything following the slashes is ignored by the JavaScript interpreter. For example:
13+
### Single Line Comments
14+
15+
Single-line comments start with two forward slashes (`//`) and continue until the end of the line. Anything following the slashes is ignored by the JavaScript interpreter.
1416

1517
```javascript
1618
// This is a comment, it will be ignored by the interpreter
17-
let a = "this is a variable defined in a statement";
19+
let a = "This is a variable";
1820
```
1921

20-
* **Multi-line comments**: It starts with a forward slash and an asterisk (`/*`) and end with an asterisk and a forward slash (`*/`). Anything between the opening and closing markers is ignored by the JavaScript interpreter. For example:
22+
You can also use them at the end of a line:
23+
24+
```javascript
25+
let b = 5; // This is also a valid single-line comment
26+
```
27+
28+
### Multi-line Comments
29+
Multi-line comments start with /* and end with */. Everything in between is ignored.
2130

2231
```javascript
2332
/*
24-
This is a multi-line comment,
25-
it will be ignored by the interpreter
33+
This is a multi-line comment.
34+
You can use it to explain more complex logic
35+
or block out code temporarily.
2636
*/
27-
let a = "this is a variable defined in a statement";
37+
let x = 10;
38+
```
39+
40+
### Real-life Examples of Comments
41+
```javascript
42+
// Change heading:
43+
document.getElementById("myH").innerHTML = "My First Page";
44+
45+
// Change paragraph:
46+
document.getElementById("myP").innerHTML = "My first paragraph.";
47+
```
48+
49+
They are also useful for debugging purposes:
50+
51+
```javascript
52+
let total = 0;
53+
// total = calculateTotal(items); // Temporarily disabled during testing
2854
```
2955

3056
Including comments in code is essential for maintaining code quality, enabling collaboration, and simplifying the debugging process. By providing context and explanations for various parts of the program, comments make it easier to understand the code in the future. Therefore, it is considered a beneficial practice to include comments in code.

0 commit comments

Comments
 (0)