Javascript - reserved words

Javascript shares a name-space with Java, the language it is derived from. So certain words are reserved, even though they may have no meaning in Javascript

boolean byte char const abstract class break case catch continue default do double else extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try var void while with

Groupings


Operators

Symbol Word What is it?
= assignment = += -= *= /= %= <<= >>= >>>= &= ^= |=
? conditional

(expression ? statement1 :statement2)

	
equivalent to if statement

if (expression)

	statement1;

else

	statement2;

	
|| logical OR used in boolean expressions

if ((expression1) || (expression2))

...

&& logical AND used in boolean expressions

if ((expression1) && (expression2))

...

| bitwise-or
^ bitwise-xor
& bitwise-and
== equality
!= inequality
< less-than
<= less than or equal
> greater-than
>= greater or equal to
<< left shift
>> right shift
>>> right_shift, fill with zeros
+ addition
- subtraction
* multiply
/ divide
% modulus
! ~ - negation
++ -- increment

variable Types

Scope Word What is it?
Script + Java boolean can be true or false
Script + Java byte A number between 0 and 255
Script + Java char a character or string
Script + Java const declares a constant value
Script + Java double double precision floating point number
Script + Java float single precision floating point number
Script + Java int 16 bit signed integer
Script + Java long 32 bit signed integer
Script + Java short 8 bit signed integer
Java static modifies type declaration making variable value persistent across method calls
Script var automatic typed variable

Class stuff

Applies mainly to Java
Scope Word What is it?
Java abstract place holder for method that can be provided by a sub class.

classes containing abstract methods can not be instantiated as they define behaviour and not details of that implementation

Java class begins a new class declaration
Java extends inheritance

class myclass extends baseclass

{

	...

}

Java implements sub-class declares which abstract classes it is implementing

class myclass extends baseclass 

implements abstract_class,...

{

	...

}

Java import imports classes from the named package

import Classes



class myclass...

{

	...

}

Java friendly the method is accessible from any class in the package
Script function defines a Javascript class or method.
Java interface used to make entirely abstract classes with no implementation

public interface myclass

{

	list abstract methods

}

Java native interfaces C code with Java. names of Native methods must match the name of the C function.

classes should instruct the linker to link against the appropriate library


public class myclass

{

	static

	{

		Linker.loadlibrary("a_C_library")

	}

	public native float the_C_function(args);

}

Java package groups classes together. the import statement will suck in all classes that belong to a package.

Package statement goes at the top of the file

Java private the method is not accesible from outside the class.
Java protected the method is not accessible from outside the class or sub-classes
Java public the method is accessible from any class.
Java super call same named method from the superclass. generally the last statement in a method that has been overridden
Script + Java this reference to the current object
Java void method that has no return value
Java with similar to pascal, the following are equivalent:

class.property1 = something;

class.method1();

	

with class

{

	property1 = something;

	method(1);

}

	

flow control

Applies to both Java and Javascript
Word What is it?
break Used within looping blocks: for, while and do. Causes flow of control to exit the block.
case A selector in a switch statement
continue Used within looping blocks: for, while and do. Program execution continues at the top of the loop.
default Marks the block of code to be executed if no other selectors in the swicth block are applicable.
do A conditional loop with the loop incrementor at the bottom of the block This loop will be executed at least once.

do

{

}

while (something);

		
else used in if statementss.
final purpose unknown
finally used on loops. Statements in the finally block will be executed unless the loop was prematurely exited with a break

while(something)

{

	statements

}

finally

{

	will be executed if the loop ran to

	normal completion

}

	

for loop, body of which is executed as many times as the condition is met. Each time around the loop the control variable is updated according to the incrementor expression

for (initial value; condition; incrementing expression)

{

}



for (i=1; i<12; i++)

{

}

if Conditional branching

if (expression)

{

	expression was true

}

else

{

	expression was false

}

return quits method and returns a value
switch

switch (variable)

{

	case value1:

	{

	}



	case value2:

	{

	}

	...

		

	case default:

}

while A conditional loop with controlling expression at the top of the block This loop will be executed only if nd while the expression is true.

while (expression)

{

}


Error handling

Scope Word What is it?
catch

try

{

	statements likely to cause an error

}

catch (exception type name)

{

	code whihc is run when the exception is caught

}

catch (exception type2)

{

	code whihc is run when the exception2 is caught

}

..

throw raises an exception

if ( validation expression)

{

	everything was fine

}

else

{

	throw new myException()

}

throws purpose unknown
try see catch

Various

Scope Word What is it?
false
Script goto flee, run away fast, never needed
in set membership
Java instanceof is the object an instance of a particular class
new constructor
null
Java synchronized used to synchronise code that is multi-threaded
java transient
true