Saturday, January 11, 2014

JavaScript Comment

There are two types of comments in JavaScript.

1) Single-line comment

It is represented by double forward slashes (//).
Ex:-
<script>  
            var a=4;
            var b=2;  
            var c=a+b;
            document.write(c);//It will print sum of 10 and 20  
</script>  

2) Multi-line comment


It can be used to add single as well as multi lines to comments.
It is represented by forward slash(/) with asterisk(*) then asterisk with forward slash.
Ex:-
<script> 
a=5;
b=6; 
document.write(a);  //it will print the value of a
document.write(b);  //it will print the value of b
/*first value of a will be print
and the the value of b */
</script> 

No comments:

Post a Comment