Javascript-Lesson 2

Case, Comments and Blocks

Case

Javascript is case-sensitive. Be very careful where and when you use capital letters.

Comments in Javascript

A single line comment is started with a double forward slash. E.G //This is a comment. This type of comment can also be used to follow a javascript statement.

A longer comment is contained in the same characters as CSS comments. E.G./*This is a much longer Javascript comment.*/

Blocks

Each group of self-contained Javascript statements (block)should be contained in curly brackets.

Javascript Variables

Variable

Variables in Javascript contain values. Such values can be numbers or even text. Variables are also of two types, 'local' and 'global'. Local variables are those whose use is restricted to a particular portion of the script. Global variables can be used anywhere in the script.

Variable Names

Variable names are also case sensitive. They can be can contain any combination of letters, digits or underscores, '_'. They can be long and descriptive (e.g. price_of_oranges) or short (e.g. x, y or z). They must start with a letter or an 'underscore'

abstract
as
boolean
break
byte
case
catch
char
class
continue
const
debugger
default
delete
do
double
else
enum
export
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
is
long
namespace
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
use
var
void
volatile
while
with
Table of Javascript reserved words

Variable names must not be one of Javascript's reserved words. I.E. words that have a specific meaning in Javascript.

Declaring a Variable

var variable_name; //What the variable is!
This is the way to 'declare' a variable. It is not obligatory to declare variables, but it makes sense to do so.

Assigning a Variable

x = 3;
is an example of assigning a variable. However a variable declaration can be combined with its assignation. e.g.
var x = 3; // x is the number of apples

Previous Lesson previous lesson next lesson Next Lesson