Sunday 26 April 2015

JavaScript Statements

WebLearn Tech

A JavaScript consist of statements that are placed inside the <script> and </script> HTML tags. The <script> tag tells the browser that everything inside the tag is a script. In HTML, JavaScript is a sequence of statements that can be executed by a web browser.

JavaScript Statements

JavaScript statements are commands to the browser. It tells the browser what function it has to do. JavaScript ignores spaces, tabs and newlines that appears in a JavaScript program. Because of that, it allows you to format and indent the program in a neat and consistent way that make the code easy to read and understand. Semicolon separates the JavaScript statements. Therefore we add semicolon at the end of each executable statements.

JavaScript Code

JavaScript code is a sequence of JavaScript statements. Each statement is executed by the browser in the sequence they are written. JavaScript code can be grouped together in blocks. A block starts with the left curly bracket and ends with the right curly bracket. The purpose of the block is to make the sequence of the statement execute together. You can break up the code using a backslash within the text string.

For example:

<!DOCTYPE html>
<html>
<body>

<h1>My Web Page</h1>
<p id="myPar">This is a paragraph</p>
<div id="myDiv">This is a Div</div>
<p><button type="button" onclick="myFunction()">Try it</button></p>

<script>
function myFunction()
{
document.getElementById("myPar").innerHTML="Hello World!";
document.getElementById("myDiv").innerHTML="How are you?";
}
</script>

</body>
</html>

JavaScript Identifiers

All programming languages must identify keyords, variables, methods, properties and labels with unique names. In JavaSript, these unique names are called identifiers. In JavaScript, these identifiers should begin with a letter, or an underscore (_) or a dollar sign ($). The other characters can be letters, digits, underscore or dollar sign. Some JavaScript identifiers are reserved as keywords and cannot be used as identifiers in a script.

JavaScript is case Sensitive

JavaScript is Case Sensitive. All identifiers, keywords, variables, methods, properties, and functions are case sensitive. A variable named myVariable is different from MyVariable, also the function getElementById is different from getElementbyID.

0 comments:

Post a Comment