02. Javascript Statements and Comments

JavaScript Statements And Comments


Javascript code
Javascript Block
Javascript Multiple Comments
Using Comments to Prevent Execution
Using Comments at te end of a Line

Javascript is a case-sensitive

Javascript statements

A JavaScriopt statement is a command to a browser. The purpose of command is to tell the browser what to do.

The semicolon is optional (according to the Javascript standard),

Using Semicolons makes it possible to write multiple statements on one line,
although good programming practice ecourages placing only one statement per line.

Javascript Code

Javascript code(or just javascript ) is a sequence of javascript statements.
Each statement is executed by the browser in the sequenced it is written

<html>
<head>
<script type="text/javascript">
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
</script>
</body>
</html>

Javascript Blocks

The purpose of a block is to make the sequence of statements executed together.

<html>
<body>

<script type="text/javascript">
{
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
}
</script>

</body>
</html>

JavaScript Comments
Javascripts comments can be added to explaine the Javascript script or to make the code more readable.

single line comments starts with //

<html>
<body>
<script type="text/javascript">
//write a heading
document.write("<h1>This is a heading</h1>");
//write two paragraphs:
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
</script>
</body>
</html>

Javascript Multiple Comments

Multiple Comments Starts with /* and end with */

<html>
<body>
<script type="text/javascript">
/* The code below will write
one heading and two paragraphs
*/
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
</script>
</body>
</html>

Using Comments to Prevent Execution

The comments is used to prevent the execution of a single code line.
<html>
<body>
<script type="text/javascript">
//document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
</script>
</body>
</html>

The comment is used to prevent the execution of a code block

<html>
<body>
<script type="text/javascript">
/*
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>");
document.write("<p>This is an another paragraph</p>");
*/
</script>
</body>
</html>

Using Comments at the End of a Line

<html>
<head>
<script type="text/javascript">
document.write("hello"); //write "Hello"
document.write("Dolly");//write "Dolly"
</script>
</body>
</html>

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams