Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.15 KB

code_commenting.md

File metadata and controls

46 lines (35 loc) · 1.15 KB

Code Commenting

First the straightforward part: how do we place comments in our code?

JavaScript

Single line comments

// Change heading:
document.getElementById("myH").innerHTML = "My First Page";

Single line comments at end of the line:

const x = 5;      // Declare x, give it the value of 5

Coding well in JavaScript: JSDoc

HTML

W3Schools Comments

<!-- Write
your comments here -->

<!-- Write your comments here -->

CSS

MDN on CSS comments

/* Comment */

/*
A comment
which stretches
over several
lines
*/

When to comment?

Now for the hard part: when to comment? When you work for different companies, you will see different styles. Embrace something you like, and then learn to let go. Google on "when to comment code?" and you'll find a big bunch of different opinions.

The general concept is, however, that it is there to help make the code more easy to understand. Note, however, that comments can also make code more difficult to understand when not applied properly.