+ 16
Why is there two ways to do a comment in JS?
There is // and /* */ Is there only a need for one of those two? What is the point of two?
20 ответов
+ 18
There is two because one is a single line comment, and the other is a multi-line comment.
You may ask why can't there just be a multi-line comment, and that's it. The single line one is there so you don't have to put an ending on it because when you do it, the computer knows it only takes up one line. Lazy people also like single-line too 😅.
+ 10
// is for single line usage.
/*Comment goes here */ is for more than one line. For one lined comments, using ' // ' is easier because there is no ending.
+ 9
One is single line, and the other in more than one line.
+ 8
These comment styles are also present in C, C++, C#, Java and some other languages too.
+ 6
There's another typical use:
If you write comments with //, you can use /* to outcomment a piece of code.
So if you have this:
// This is code doing stuff
said_code();
You can use the other style to 'deactivate' this code easily:
/*
// This is code doing stuff
said_code();
*/
+ 6
HTML Master, that comment is a multi-lined, so technically it would be two. All that does is save you time for long lists.
+ 6
//single line comment
/*
multi-line
comment
*/
I think the most important one is the second one but they made both of them for you to choose which of these your comfortable with. For me I prefer single line comment than multi-line because is simple and fast when I'm writing them.
So the question is what do you prefer? Because both of them can be used to accomplish the same task.
+ 5
There is a third comment. It is this:
/***
*/
It is the comment that creates a star for every new line, so its great for listing. Basically, each different type of comment has its own purpose for JavaScript.
+ 3
Good point Regulation. But its harder when trying to space things out a lot in a single-lined comment. It depends on how people use comments.
+ 3
Guys, do you read answers?
It's all in here already!
+ 2
The single line is meant for quick notes, or text. The multi line is better for longer texts.
+ 2
Also, technically, you can endlessly write a single-line comment in code. It would still take up one line of code.
+ 1
It is made to be a two way in other to have a comment for single line and multiline
//This is for single line comment.
/*
THIS
IS
FOR
MULTI-LINE
*/
+ 1
there two comments: "//"inline comment and "/**/". multi-line comment
you can't use inline comment in two lines together. inline comment is used to write a little comment in a line.
And, multi-line comment is used to write a big comment or description.you can use it in some lines together.
0
It is for lazy people 😜😂
the single line comment!!
0
//makes it easier for you when you're running your codes and is giving errors that you can't easily identify so you comment line by line at a time till you can identify the problem and fix it. Otherwise one is single line and the other is multi line
0
// is used for single line comment
While /* */ is used for multi line comment.
0
/**/ multi line comment
// Single line comment
0
the first is used for single line comment and the second is used for multi-line comments but it’s not only there in JS it is available in most of the programming languages if i am not mistaken. i’d like to use the second one it provides me an easy way of explaining my code as i don’t need to place two slash before i comment on a new line