02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Multi line Comments

In every developers life there comes a time where he just wants to comment a few things out without deleting them. You already know how to comment line by line but wouldn't it be nicer (for you and your fingers) if you could cancel out a full block of code?

We have already studied commenting in earlier videos and discussed the single line comment in detail. We won't go in detail about this but will just have a quick review of the previous video before moving ahead to multi-line comments.

We all know that at times we need to hide part of a lengthy piece of code. As we said earlier, we do not want to delete it – just hide it through commenting it out so we can use it again when required. This is the main reason we use the concept of comments, and we use the single line comment to hide one line in the program by placing // before the line.

Now let's dive into multi-line comments. We have studied how to hide single line of code which is not required. What if there are multiple lines to be hidden for future use? One option is to use single line comments for each unwanted line of code. This is a good answer and a correct one, but is it the easiest or smartest way to do it? If you need to comment out a large block of code, will you still use the same process? There must be a better solution.

And presto – there is! The best way to save your fingers and comment out multiple lines in code is to use Multi-line comments. The way we create multi-line comments is by opening and closing the block of code using two symbols: /* to open a comment and / to close one. This will comment out any number of lines between / and */. This way you can skip about 50 or 100 lines within 5 seconds. You must close a multi-line comment, contrary to the single line comment. Multi-line comments are like parenthesis: if you open one you must close it as well.

Comments are more than just to ignore code, as we said before. Comments are a very powerful and useful documenting feature from "by the way" notes to yourself all the way to really advanced commenting structures known as ASDocs – those are comments that have a structure, but are not used as part of the code. They actually create Flash help documentation.

Video Transcript

00:01Now that we got these concepts we're going to repeat and kind of regurgitate them
00:06We're going to learn another way of how to block code out right now
00:10We have a double slash to get rid of code. What if we want to get rid of a lot of lines?
00:15It takes a lot of energy to
00:17Get rid of so many lines, so there's simpler ways to do it. So the way that I would
00:23Grouply get rid of some code for example these lines, which aren't really
00:28relevant to our application
00:30they're just for me to
00:32Help me figure things out the way we do that is we we type slash
00:38Then ship shift 8 excuse me for stuttering
00:42Happens sometimes when I'm excited
00:46bracket
00:47Well brackets have nothing to do with it
00:50So we want to put a slash and then a star and then when we're done
00:54We're gonna put a star again
00:55And then a slash and anything between these lines are gonna be dimmed out and our application is going to ignore
01:02So let's do this one more time
01:06Perfect. So now we have all the items that we don't want traced out
01:10Well, we could always grab our and grab this one and do and put this all in one bucket
01:17And grab that and put that all in one bucket. So now everything
01:22Everything inside here is being dimmed by this
01:27Chunk and
01:29everything inside here is
01:32The second chunk and here we could see how we
01:37Commented things out in one line

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!