![]() |
VOOZH | about |
In programming, our first consideration is usually the machine β how the computer is reading and interpreting the code we write. However, itβs equally important to consider the people who will be reading and working with the code. Whether youβre working with a team or on your own, you will need to learn to properly comment and structure your code for human readers.
Comments are annotations in the source code of a program that are ignored by the interpreter, and therefore have no effect on the actual output of the code. Comments can be immensely helpful in explaining the intent of what your code is or should be doing.
As a developer, it can be frustrating to delve into code written by someone else that was not properly commented, and itβs remarkably easy to forget what your own code meant when youβre no longer immersed in the context of a program. Commenting your code early on will reinforce good programming habits throughout your career to avoid these issues later on.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
JavaScript is a high-level, object-based, dynamic scripting language popular as a tool for making webpages interactive.
Browse Series: 37 tutorials
Software engineer and open source creator
Community and Developer Education expert. Former Senior Manager, Community at DigitalOcean. Focused on topics including Ubuntu 22.04, Ubuntu 20.04, Python, Django, and more.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This comment has been deleted
Hey, we forgot to mention /*! multiline comment blocks!
This blog is very clear about the content, and this can be useful to read and learn more knowledge from this blog.
You might at least mention that the /** */ syntax is for jsdoc and point people to the jsdoc docs.
Thank you for the article! Basing on our experience in GBKSOFT, itβs pretty useful when the team is working on the project. I assume that comment may come in handy when you have a cross-functional team and work on Node.js so everyone who knows JS can check the code.
It should be noted that comments should be only put where they are needed, as they need to be maintained along the code, and become easily out-of-date, and become more confusing than helpful.
Code readable by itself should be preferred over commented code. In many of the examples above the comments are not necessary because the code is self explaining, e.g.:
// Initialize a function
function alphabetizeOceans() {
// Define oceans variable as a list of strings
const oceans = ["Pacific", "Atlantic", "Indian", "Antarctic", "Arctic"];
// Print alphabetized array to the console
console.log(oceans.sort());
}
Hereβs an article about that topic, and youβll find many more on the internet: https://www.freecodecamp.org/news/code-comments-the-good-the-bad-and-the-ugly-be9cc65fbf83/
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow β whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.