logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g JavaScript / Java Site

BellaOnline's JavaScript / Java Editor

g

Comments in JavaScript

Guest Author - Julie L Baumler

Comments are just that, comments that you put in your JavaScript or HTML to explain what is going on. There are several ways to put comments in your JavaScript code. Comment syntax how to tell the script or document that something is a comment and not data or code is very simple. Writing good comments is harder, and from looking at code (my own included), the hardest part seems to be actually doing it!

JavaScript has 2 types of comments, a single line comment and a multi-line comment.

The single line comment in JavaScript starts with two forward slashes (//) and ends at the end of the line (technically, immediately before the line terminator character). Single line comments are particularly useful for short notes.

// This is a single line comment
data="my data" // This is a single line comment too

A multi-line comment in JavaScript starts with a forward slash followed by an asterisk (/*) and ends with an an asterisk followed by a forward slash (*/). Everything between the /* and */ is considered a comment. This type of comment can span multiple lines. It is also possible to put this type of comment in the middle of a line of code, if it does not span multiple lines, but this is rarely useful.

/* this is line one of a multi-line comment
this is still part of my comment
this is the last part of my comment */

/* this is a multi-line style comment on a single line */

You often see extra asterisks added to multi-line comments to create decorative information boxes, such as:

/*********************
* My Functions *
*********************/

Multi-line functions are particularly useful at the beginning of a program or section of a program to describe what the program is intended to do and how it does it.

Comments are used for two purposes. As you write code (or even before you write it!), you should write comments that will allow another person to understand what the program is doing (or supposed to be doing.) Even if you don't expect anyone else to ever read your code, you'll be surprised how much you can forget if you want to make changes after a few weeks or months.

Also, particularly in scripting languages like JavaScript, comments are often used as part of the debugging process. You can put in code to use for debugging and comment them out when you are done using them or comment out sections of code that you think are causing problems or are changing to add new functionality. When you do this, be particularly careful not to put a single line comment on the line in front of the beginning of a multi-line comment. This uncomments the rest of the multi-line comment, which will almost certainly cause an error.
This site needs an editor - click to learn more!

Add Comments+in+JavaScript to Twitter Add Comments+in+JavaScript to Facebook Add Comments+in+JavaScript to MySpace Add Comments+in+JavaScript to Del.icio.us Digg Comments+in+JavaScript Add Comments+in+JavaScript to Yahoo My Web Add Comments+in+JavaScript to Google Bookmarks Add Comments+in+JavaScript to Stumbleupon Add Comments+in+JavaScript to Reddit




A First JavaScript Program
JavaScript Beginners Resources
JavaScript/Java Newsletter
RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map


For FREE email updates, subscribe to the JavaScript / Java Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Hearing Dog Tool - Adding Randomness

Hearing Dog Training Tool setTimeout()

GCJ - an Independant Java Implementation

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor