Code Commenting

In programming, we use comments to comment code literally or to deactivate code without deleting it. There are two different main types of comments, the single line and multi line comments. In this course, I will use the single line comment in most of my demonstrations.

Single Line Comment

// This is a single line comment
A double slash is used for commenting on a single line of code.

Usually, we use this to describe what the code is doing. Also, remember javascript will completely ignore anything that is a comment. So anything that comes after // will not be executed and this can be useful in dividing our code into different sections and explaining what other pieces of code are doing in our code.

// sum of two numbers
let x = 10;
let y = 20;
console.log(x,y) // 10 20

let total;
total = x + y;
console.log('Sum of x and y is:', total); // Sum of x and y is 30
If you have trouble understanding the code, don't let it bother you. This is a random example to demonstrate single-line comments.
This image will help you understand how I was commenting on my code.

Multi-Line Comment

Now, let's look into multi-line comment. It is generally used to comment out multiple lines of code that we don't want to be executed for some reason.

is a
Multi Line
Multi-line comments start with /* and end with */
Here we can clearly see the second half of the code is inactive.

In VSCode or in the majority of the code editors, you use the Command + / or Ctrl + / shortcut to comment out code. According to the necessity, the editor will care what type of commenting method to use.

You've successfully subscribed to Leewardslope
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.