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

Single Line Comment

We already discussed comments during the very first video of this course. There the discussion was brief, but here you can find detailed information about mainly the single line comment.

When we want the compiler to ignore a line or number of lines in the program, we use the concept of the comment. By mentioning "single line comment," we mean that the code to be ignored (or a comment added to it) is single line and not multiple. However, single line commenting can be performed multiple times to make sure multiple lines are omitted by the compiler.

Syntax for single line comment

There isn't anything difficult to remember when it comes to the syntax of the single line comment. We just need to type // before any line or part of the line for the program to ignore it. The line is still in the program, but is not read by the compiler during the process of compilation. The general syntax is //trace("Yo mama wears army boots!");. For example, let us consider //trace("this line is commented out"); As soon as we placed // before trace, the whole line is neglected by the compiler and the text inside the double quotes is not printed.

Why does the single line comment even exist?

Many of you might wonder why we need to learn the theory of commenting, when its use is limited to commenting out a certain line when it's certainly much more simple to just delete it. Don't forget that deleting means that line is gone forever – play Taps for it. What if you need it later – especially if you're using it for testing purposes? You get to retype it, that's what. Now, if only you'd commented it out.... remove the // and you're back in business! That line is again part of your program. When commenting, nothing is deleted but the commented line is just ignored by the compiler and can be reused (or not) anytime you want!

Equally useful to having the compiler ignore a line, single line comments can also be used to describe the usage of a particular line within the program. Developers can write comments beside the actual code, such as:

trace("I am inside the newName function"); // this outputs only when the newName function is called

This is useful for developers maintaining or updating your code and learners because they can read the comments beside the line to understand its usage and why that line was included in the code.

Video Transcript

00:00We've learned a new command, we've learned how to trace things into the output, and we can see hello world, I am Ben Fallow.
00:07But if you've noticed, we've actually learned two concepts at the same time.
00:13Because we've learned that we had to send information to a function, which our trace is a function.
00:20We called the function trace and we sent to it a value.
00:23And that value then was outputted into our output panel.
00:27Now the value that we sent to it in Flash is a string we call this, because this value is wrapped around quotes or double quotes.
00:36And they represent strings or words.
00:39And in Flash we call these strings strings.
00:42And there's different languages that call it different names, but then it's the same thing.
00:48It's a wrapped string.
00:51Which is a native variable in Flash, which we're going to look into what these variables are action, what are variables.
00:58Right now we're working with live content.
01:01So now that we've got our heads around a basic concept of strings, let's comment this code out.
01:07And the way we comment code out is by typing slash slash.
01:14So I'm going to do it for both lines and I'm going to comment out my trace.
01:19And I'm going to move it down a line so we can start typing numbers.

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!