Saturday 25 January 2014

comments in javascript

JavaScript Comments
·         Comments will not be executed by JavaScript.
·         Which is useful for the programmers for more readable
Types of Comments: 2 types
1.    Single line comments
2.    Multiline comments
Single line comments start with //.

The following example uses single line comments to explain the code:

<!DOCTYPE html>
<html>
<body>

<h1 id="myH1"></h1>

<p id="myP"></p>

<script>
// Write to a heading:
document.getElementById("myH1").innerHTML="Welcome to my Homepage";
// Write to a paragraph:
document.getElementById("myP").innerHTML="This is my first paragraph.";
</script>

<p><strong>Note:</strong> The comments are not executed.</p>

</body>

</html>

/*multiline comments*/
<!DOCTYPE html>
<html>
<body>

<h1 id="myH1"></h1>

<p id="myP"></p>

<script>
/*
The code below will write
to a heading and to a paragraph,
and will represent the start of
my homepage:
*/
document.getElementById("myH1").innerHTML="Welcome to my Homepage";
document.getElementById("myP").innerHTML="This is my first paragraph.";
</script>
<p><strong>Note:</strong> The comment-block is not executed.</p>
</body>
</html>

No comments:

Post a Comment