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

Creating Javascript Comments

We'll get you familiar with some syntax first. In JavaScript you can comment a single line by putting two forward slashes in the start of that line like this:

// one line comment

Or if you have a lot more to say (multiple lines in a comment,) you can achieve that with ease by putting “/” at the start and “/” at the end like this:

/* This function requires two parameters: a string and a boolean. It then returns a boolean that indicates if the user has a fat butt or not. Call it like this for example: gotFatButt(userName, isFat); */

How can Comments help us?

Comments can be used to achieve discipline in coding. First you can comment out any code which you don’t want to run. If you delete your code there's always a chance you’ll regret it later when suddenly you figure out it's just what you need. Instead of deleting, just comment out blocks of code you think you might need again. (It's almost guaranteed that if you delete a block, you WILL need it later!)

Comments are a great way to describe your code and leave behind extra information for you and others that work with your code. A good program needs a good strategy and many times a few comments can help and improve overall understanding of your code. Comments are used as documentation many times in code as a way to share with others and yourself insight about your code. Many times we comment out debugging functions or other lines of code that we still want available but don't want them to run.

These tips may make your life easier in the future.

Video Transcript

00:01So we covered Strings and that's really all you really need to know the basics of strings to get started and working with
00:08JavaScript now the next item I want to talk about I want to talk about numbers
00:13We said the numbers exist now before that I want to show you when I use this
00:18backslash
00:19star I open a comment and I could comment this whole area by just starting with that ending with that now all of this is
00:28In the comment and if I save my file right now, and I rerun it
00:32We'll see that we're not gonna get any alert, and that's exactly what I hope to happen
00:36Alright, so I'm gonna choose a few spaces, and if we're ready talking about comments
00:40I could also put a double double space. No, sorry double slash, and then I could put here a one
00:48line

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!