Skip to main content

JavaScript Statements

avaScript is a sequence of statements to be executed by the browser.

JavaScript is Case Sensitive

Unlike HTML, JavaScript is case sensitive - therefore watch your capitalization closely when you write JavaScript statements, create or call variables, objects and functions.

JavaScript Statements

A JavaScript statement is a command to a browser. The purpose of the command is to tell the browser what to do.
This JavaScript statement tells the browser to write "Hello Dolly" to the web page:
document.write("Hello Dolly");
It is normal to add a semicolon at the end of each executable statement. Most people think this is a good programming practice, and most often you will see this in JavaScript examples on the web.
The semicolon is optional (according to the JavaScript standard), and the browser is supposed to interpret the end of the line as the end of the statement. Because of this you will often see examples without the semicolon at the end.
Note: Using semicolons makes it possible to write multiple statements on one line.

JavaScript Code

JavaScript code (or just JavaScript) is a sequence of JavaScript statements.
Each statement is executed by the browser in the sequence they are written.
This example will write a heading and two paragraphs to a web page:

Example

<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 another paragraph.</p>");
</script>

Try it yourself »

JavaScript Blocks

JavaScript statements can be grouped together in blocks.
Blocks start with a left curly bracket {, and end with a right curly bracket }.
The purpose of a block is to make the sequence of statements execute together.
This example will write a heading and two paragraphs to a web page:

Example

<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 another paragraph.</p>");
}
</script>

Try it yourself »
The example above is not very useful. It just demonstrates the use of a block. Normally a block is used to group statements together in a function or in a condition (where a group of statements should be executed if a condition is met).
You will learn more about functions and conditions in later chapters.

Comments

Popular posts from this blog

Invigilators caught helping relatives during exams

HYDERABAD: The Chairman Board of Intermediate and Secondary Education (BISE) Hyderabad Abdul Aleem Khanzada, on Monday, detected four invigilators helping their sisters and daughters in cheating during Higher Secondary School Certificate Part-I and Part-II Annual Examinations 2012. According to a spokesman, the Chairman BISE Hyderabad caught these invigilators red handed during his surprise visit to examination centres of Tando Allahyar and Chambar along with his team members. While taking spot action, the Chairman BISE Hyderabad has relieved these four invigilators from the duty of conducting examinations. Besides, he also caught red handed 21 male and female candidates who were engaged in copying in the examinations. The other vigilance committees of the board which conducted surprise visits to Hyderabad, Shaheed Benazirabad, Matiari, Tando Allahyar, Tando Muhammad Khan, Badin, Thatta, Jamshoro and Dadu districts detected 144 male and female candidates engaged in copying during the

Ufone TV Commercials Free To View or Download

30 Second Offer Sim Lagao Offer Ufone Winner Offer