Javascript (intro)

Javascript (not to be confused with Java) is a language mainly used in web pages. All popular modern web browsers include a Javascript interpreter which will run any Javascript code included in a web page, allowing the page to be programmatically manipulated on the user’s machine (rather than just on the web server).

Javascript is a dynamic language very semantically similar to Pigeon, though its syntax superficially resembles that of Java and C. The major new concepts which we didn’t see in Pigeon include:

infix notation and free-form syntax

Whereas Pigeon uses prefix notation, Javascript uses the more familiar infix notation, e.g. (3 + 5) rather than (add 3 5). Also, rather than treat indentation as significant, Javascript allows you to indent your code however you like.

nested functions and closure

Javascript allows a function to contain other functions defined within it. A function defined inside another forms a special relationship with its containing function called closure, wherein a call to an inner function retains the local variables of its containing function(s).

methods, object links, and the new operator

Javascript includes a few simple mechanisms to facilitate object-oriented programming (which we explain more fully in a later unit).


The exception mechanism helps us better cope with errors in code. In short, when an error occurs in execution, an “exception” is “thrown” which may then be “caught” (intercepted) and “handled” (dealt with).

Comments are closed.