Comments
are used to document the source code. Comments in javaScript, makes the program
more readable. Comments are ignored by JavaScript.
Suppose
you written thousand lines of program, with out proper documentation, after
some time, for the owner of the application also, it is very difficult to
figure out what was written.
Comments solve this problem:
By using
comments, you can document your code at the time of writing program. Comments
won't affect your program execution. Comments simply document your code.
Javascript
support 2 kinds of comments.
a.
Single
line comments
b.
Multi
line comments
Single line comment :
Single
line comments starts with //
// It is a
single line comment
Multi Line comment
Multi line
comments are encoded in /* */
/* I am a
mulltiline comment */
sample.html
<!DOCTYPE html> <html> <head> <title>Variables</title> </head> <body> <script type="text/javascript"> /* Java script is weakly typed language Author: Hari krishna */ var a = 10; document.write("Value of a is " + a + "<br />"); a = "Hello World"; // Assigning string document.write("Value of a is " + a + "<br />"); a = true; // Assigning boolean document.write("Value of a is " + a + "<br />"); a = 10.09; // Assigning number document.write("Value of a is " + a + "<br />"); </script> </body> </html>
No comments:
Post a Comment