build-website-header
spacer-image
 

Starting JavaScript Part 1 - Main Characteristics

The Main Characteristics of JavaScript are:

  • JavaScript is case sensitive
  • JavaScript statements usually end in a semi-colon but this is not mandatory.
  • Braces are Used to group statements.
  • Comments are used to make the code easier to understand

Here we will go through and examine these characteristics in more detail

Case Sensitive

Because JavaScript is case sensitive then:

X=20 is not the same as x=20  and Newvar=20

Semi-colon Use

JavaScript consists of two elements statements and comments. Anything that isn't a comment is interpreted as a statement. Statements an span more than one line or you can have multiple statements on a single line.

The JavaScript interpreter will determine itself whether or not a statement has ended with or without the semi-colon; however using the semi-colon is the official way of telling the interpreter that the end of a statement has been reached. So although:

x=20
x=20;

both assign the value of 20 to the variable x, one uses the semi-colon the other doesn't, but they both work. It is good practise to always use the semi-colon as it makes your script far easier to read and debug.

Using Braces

Braces come in pairs: an opening brace (right brace).. { and a closing brace (left brace)..  }. They are used for grouping statements together in blocks. They are typically used for functions and if/else test. For Example

if (x==y)
{
statement 1 of true
statement 2 of true
statement 3 of true
}
else
{
statement 1 of false
statement 2 of false
statement 3 of false
}
 

In the example if the x is equal to y then the block of true statements will be run if it is not the block of false statements will be run.

Using Comments
Comments can be either single or multi line. A single line comment start with two backslashes e.g.

//This is a single line comment
////This is also a single line comment extra /s are simple ignored
/ this is / and illegal comment

Multi-line comments start with /* and end with */   e.g.

/* valid
multi line comment */
/* Invalid comment as no end
Invalid comment as no beginning */







 

 

 

 

 

 

 

 

 

 










Google
Web www.build-your-website.co.uk