7554425D-0054-440D-B95E-D2ABC13D62CD Created with sketchtool.
Your Saved Info Packages

View your saved Course or Program Packages containing pricing and detailed curriculum.

Speak with a Learning Advisor.

Have any questions? We'll call you.

Fill out the form below and a Learning Advisor will reach out at a time convenient for you.

Please pick a valid date and time between 9 AM and 8 PM eastern (Monday to Friday)

By clicking "Book a call," you accept our Terms and will also receive exclusive offers and updates about new courses, workshops and events.

JavaScript Tutorial

JavaScript Comments

Ready to start your career in Development? Find out more about BrainStation's Web Development Bootcamp

Comments are powerful programming constructs to explain complex code blocks, what it does and why it was implemented in a particular way. As systems and websites evolve, Developers always end up writing code that is complex. It might make complete sense to the original author or Developer but might not be obvious to Developers new to the team or the ones who are looking at the code for the very first time. In such cases, comments are a very powerful tool to explain the thought process and decisions made while writing a block of code.

JavaScript also supports comments - both single line comments for quick explanation and multi-line comments for a detailed explanation or documentation. Let’s take a look at them.

Single-line comment

Single line comments are very useful to add a quick comment or explanation over a line of code. In JavaScript, a single line comment can be added by using two forward slashes //. Below are some examples of single line comments.

// this will output ‘hello world’ to the browser's console.
console.log(‘hello world’);

result = 3 + 7 // comments can also follow a statement like this

Multi-line comment

Sometimes, a single line is not enough to document or explain why certain code is written in a particular way or what it does. This is when a JavaScript Developer can use multi-line comments. A multi line comment in JavaScript can be added by writing the comment between a forward-slash followed by asterisk /* and asterisk followed by a forward-slash */. Below are some examples of multi line comments.

/* Add two numbers and
   Store the output in a variable called result.
   Also, print the output to the browser’s console
result = 6 * 5
console.log(‘Multiplication result is: ‘, result);
Set Password

You already have an account with BrainStation, but you still need to set up a password.