+ 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?

5th Feb 2020, 10:51 PM
Blue Blitz Coder
Blue Blitz Coder - avatar
20 Réponses
+ 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 😅.
5th Feb 2020, 10:54 PM
Green Ghost
Green Ghost - avatar
+ 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.
5th Feb 2020, 11:04 PM
[No Name]
[No Name] - avatar
+ 9
One is single line, and the other in more than one line.
5th Feb 2020, 11:01 PM
Bob Brown
Bob Brown - avatar
+ 8
These comment styles are also present in C, C++, C#, Java and some other languages too.
5th Feb 2020, 11:48 PM
Sonic
Sonic - avatar
+ 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(); */
5th Feb 2020, 11:31 PM
HonFu
HonFu - avatar
+ 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.
6th Feb 2020, 2:33 AM
ᗰᗩᔕ丅ᗴᖇ
ᗰᗩᔕ丅ᗴᖇ - avatar
+ 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.
6th Feb 2020, 7:10 AM
Stanley K Ludovick
Stanley K Ludovick - avatar
+ 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.
6th Feb 2020, 2:24 AM
HTML Master
HTML Master - avatar
+ 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.
6th Feb 2020, 9:17 PM
Green Ghost
Green Ghost - avatar
+ 3
Guys, do you read answers? It's all in here already!
7th Feb 2020, 1:18 PM
HonFu
HonFu - avatar
+ 2
The single line is meant for quick notes, or text. The multi line is better for longer texts.
6th Feb 2020, 8:48 PM
Regulation
Regulation - avatar
+ 2
Also, technically, you can endlessly write a single-line comment in code. It would still take up one line of code.
6th Feb 2020, 8:50 PM
Regulation
Regulation - avatar
+ 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 */
6th Feb 2020, 9:27 PM
Mayokun Adewuyi
Mayokun Adewuyi - avatar
+ 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.
7th Feb 2020, 1:16 PM
ISTIAQUE ZAMAN
ISTIAQUE ZAMAN - avatar
0
It is for lazy people 😜😂 the single line comment!!
7th Feb 2020, 7:23 AM
Hafeesa Hashim V
Hafeesa Hashim V - avatar
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
7th Feb 2020, 10:38 AM
Buhle 💃💃💃
Buhle 💃💃💃 - avatar
0
// is used for single line comment While /* */ is used for multi line comment.
7th Feb 2020, 11:53 AM
Mohammad Ayaz Alam
Mohammad Ayaz Alam - avatar
0
/**/ multi line comment // Single line comment
7th Feb 2020, 4:54 PM
Mohammad Amin Sultan
Mohammad Amin Sultan - avatar
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
7th Feb 2020, 7:51 PM
Tarek Moustafa
Tarek Moustafa - avatar