ABSTRACT

JavaScript was designed and implemented in ten days in 1995 by Brendan Eich, and then at Netscape Communications Corporation, with the goal of creating an amateur-friendly scripting language embedded into a web browser. This chapter utilises JavaScript to introduce several aspects of functions: argument passing, scope, the handling of free variables, closures, and anonymous and higher-order functions. A JavaScript program is made up of scripts and modules, each containing a sequence of statements and function declarations. Statements include variable declarations, assignments, function calls, conditionals and loops, among others. References allow multiple variables to refer to the same object. In JavaScript, arguments are fully evaluated before the call and their values are assigned to the parameters left-to-right. Variables used but not declared inside the function are called free variables. A binding is an association of a name with an entity. The scope of a binding is the region of code where a particular binding is active.