Tutorial - Add a comment in NodeJS

Tutorial - Add a comment in NodeJS

Comments are annotations in the source code of a program that are ignored by the interpreter. As a result, they have no effect on how the code runs or the output it produces.

But they can be used to explain what your code is doing to any humans that attempt to read your code. Therefore, they can be incredibly useful to both others and your future self when you try to figure out what the code you wrote in the past does.

Let's go through the two ways to comment in Node.js.

Single-Line Comments:

The first way is the single-line comment by using two forward slashes (//).

Here's what it looks like:

Node.js
 
// Anything after the two slashes is commented out.

Anything after the two slashes (//) will be commented out.

You can add these comments inline with your code as well:

Node.js
 
const tacoJohns = "Very Good!" // Comment explaining the variable

There isn't a way to end a single line comment on a line, so make sure you don't put any code after the // hashes unless you don't want it to be seen by the interpreter.

Inline comments can be super useful, but they can make your code look messy if you use them too much.

Block Comments:

The second way is called block comments. These are written with open (/*) and close (*/) tags.

Here's what it looks like:

Node.js
 
/* Comment on
multiple lines */

Everything between the open and closing tags will be excluded.

Block comments will give you more options compared to the // syntax we covered earlier. And even allow you to block out entire sections of code if you desire to do so.

Thanks for reading and happy coding!

Originally published by  Nick Major  at  coderrocketfuel.com


====================================================

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow me on Facebook | Twitter

Moving from NodeJS to Go

NodeJS Logging: What should you know about logging?

Start Working with Voice Driven Application with Nodejs

Node.js / Javascript performance coding tips to make applications faster

How to Build a URL Shortener With Node.js and MongoDB


node-js javascript web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Top Node.js Development Companies and Expert NodeJS Developers

A thoroughly researched list of top NodeJS development companies with ratings & reviews to help hire the best Node.JS developers who provide development services and solutions across the world. List of Leading Node.js development Service Providers...

Hire Web Developer

Looking for an attractive & user-friendly web developer? HourlyDeveloper.io, a leading web, and mobile app development company, offers web developers for hire through flexible engagement models. You can **[Hire Web...

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.