0% found this document useful (0 votes)
74 views4 pages

JavaScript Code and Comments Guide

Uploaded by

Prem Lal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views4 pages

JavaScript Code and Comments Guide

Uploaded by

Prem Lal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

rouped together in code blocks

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Statements</h2>
<p>JavaScript code blocks are written between { and }</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="demo1"></p>
<p id="demo2"></p>
<script>
function myFunction() {
[Link]("demo1").innerHTML = "Hello Dolly!";
[Link]("demo2").innerHTML = "How are you?";
}
</script>
</body>
</html>

You can break a code line after an operator or a comma.

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Statements</h2>
<p>
The best place to break a code line is after an operator or a comma.
</p>
<p id="demo"></p>
<script>
[Link]("demo").innerHTML =
"Hello Dolly!";
</script>
</body>
</html>
6. JavaScript Comments
 Single line comments
 Single line comments at the end of a line
 Multiple lines comments
 Single line comment to prevent execution
 Multiple lines comment to prevent execution

Single line comments

<!DOCTYPE html>
<html>
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
// Change heading:
[Link]("myH").innerHTML = "JavaScript Comments";
// Change paragraph:
[Link]("myP").innerHTML = "My first paragraph.";
</script>
</body>
</html>

Single line comments at the end of a line

<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Comments</h2>
<p id="demo"></p>
<script>
let x = 5; // Declare x, give it the value of 5
let y = x + 2; // Declare y, give it the value of x + 2
// Write y to demo:
[Link]("demo").innerHTML = y;
</script>
</body>
</html>

Multiple lines comments

<!DOCTYPE html>
<html>
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
/* The code below will change
the heading with id = "myH"
and the paragraph with id = "myP" */
[Link]("myH").innerHTML = "JavaScript Comments";
[Link]("myP").innerHTML = "My first paragraph.";
</script>
</body>
</html>

Single line comment to prevent execution

<!DOCTYPE html>
<html>

You might also like