Thursday 3 July 2014

Chapter 3: JavaScript Statements

JavaScript statements:
JavaScript like in most programming languages is grouped into statements, to say piece by piece what your script to do.
Each JavaScript statement should end with the semicolon and don’t forgot about it because you will into problems. Just because of this you can put multiple statements in one line, but don’t do this it makes it hard to read. Split it into multiple lines.

Multiple statements in one line:
Example:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>

<script>
alert("this is an alert"); console.log("This is an message in the console of the browser.");
</script>
</body>
</html>



Multiple statements in multiple lines:
Example:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>

<script>
alert("this is an alert");
console.log("This is an message in the console of the browser.");
</script>
</body>
</html>



JavaScript might be case-sensitive but not sensitive to spaces and line return between different pieces of the language.
Example:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>

<script>
console.log("Hello World");
console . log (" Hello World " ) ;
console.
log
("Hello World");       

</script>
</body>
</html>


All above examples are correct.

No comments:

Post a Comment