call function prototype function


Function.prototype.call = function (thisObject) {
return this.apply(thisObject, Array
.prototype.slice.apply(arguments, [1]));


The term callback is given to a function that is passed to another function or stored in an object with the intention that it be called at a later time. Callbacks are commonly used in subscription patterns where functions are to be called when some event has occurred. In browser applications, an event handler function is a callback.

var statusHolder = (function () {

// Produce an object containing three functions:
//    getStatus(): get the value of a private status variable.
//    addCallback(callback): subscribe a function that will be
//        called when the status changes.
//    setStatus(newStatus): Change the status and inform the
//        subscribers.

    var status,              // The private status variable.
        subscribers = [];    // The list of subscribing functions.
    return {
        getStatus: function () {
            return status;
        addCallback: function (callback) {
        setStatus: function (newStatus) {
            status = newStatus;
            subscribers.forEach(function (callback) {


An object's methods return the same object... Blah.

case reserved word

Also see switch statement.

In many of the world's writing systems (including Latin, Greek, Cyrillic, and Armenian), letters come in two forms: lower case (or small or minuscule) and upper case (or big or capital or majuscule). For the purpose of spelling, the two cases are equivalent, but in usage the cases are distinct and Unicode gives then unqiue character codes, so while I and i are the same letter, they are different characters and have different codes.

'I' === 'i'    // false

This language is case sensitive. Case in names and strings case is significant, so 'cat' and 'Cat' are not the same string and getElementById and getElementByID are not the same name. Every reserved word is entirely lower case.

For each lower case letter there is a unique upper case letter, and for each upper case letter there is a unique lower case letter, with the following exceptions:

The toLowerCase String prototype function produces a string in which all of the upper case letters are replaced with their lower case equivalents, so 'VISA'.toLowercase() produces 'visa'. The toLocaleLowerCase String prototype function produces a string in which all of the upper case letters are replaced with their lower case equivalents using the local convention, so for programs in a Turkish environment, 'VISA'.toLocaleLowerCase() might produce 'vısa'.

These functions are aware of case:

In regexp pattern matching, the matching of letters is case sensitive. The regexp flag i makes the matching of letters case insensitive.

/v/.test('VISA')     // false
/v/i.test('VISA')    // true

The reserved word case is used for a completely unrelated purpose in the switch statement.

catch reserved word

See try statement.


ceil Math function ceiling

The Math.ceil(number) function converts a number into an integer. If the number argument is already an integer, it simply returns the number. Otherwise, it returns the lowest integer that is greater than the number. If the number is less than 0 but greater than -1, the result is -0. The function could be implemented like this:

Math.ceil = function (number) {
    return -Math.floor(-number);




charAt String prototype function



charCodeAt String prototype function


circular definition

See definition, circular.

class reserved word



code point


code unit



A comment is text in a compilation unit that is ignored by the compiler. A comment can be used to document a program, giving information about its construction and operation. There are two forms of comment, the // comment and the /* block comment.

It is important to document programs to help a reader (perhaps future you) understand how the program works. It is even more important to keep comments uptodate. Incorrect comments are worse than no comments.

compilation unit

A program is delivered as one or more compilation units. In an HTML application, each <script> tag delivers one compilation unit. Scripts are compiled and executed immediately. The result of the execution could be to output a solution. More commonly, however, the result of execution is to create and modify objects in the global environment, setting up callback functions that will execute later in response to user actions and other events. For example, in a web browser, each compilation unit will be attaching event handlers to DOM nodes and installing global objects and functions that will provide services to the event handlers. The program does not stop when the compilation units have finished running. From the user’s perspective, that is when the program starts.

A compilation unit contains a sequence of zero or more statements. The statements are executed sequentially. After a statement has finished executing, the next statement is executed. After executing the last statement, the compilation unit's turn is finished, at which time another compilation unit might be exececuted, or an event might be fired.

A compilation unit executes in a global scope, so every variable created by the var statement or function statement will be global. There is a phenomenon called hoisting that can alter the sequential flow of the compilation unit. Hoisting affects the var statement and the function statement. Every global variable created by one compilation unit will be available to all subsequent compilation units.

In an HTML application, each on- event attribute delivers a deferred compilation unit. Each on- event attribute is compiled and executed when an event is dispatched. Use of on- event attributes is not recommended.


A compiler is a program that translates a source program into an executable form. In this language, the compiler can be accessed by the eval global function and the Function global function.


concat array prototype function


concat string prototype function


conditional statement

A conditional statement alters the flow of a program, which normally executes from top to bottom, by selecting one path from two or more possibilities, deciding based on the value of an expression or the occurence of an exception.

const reserved word


A constant is a name with a fixed value. Each of these names can be used as an operand, but they may not be used as an lvalue.

Strictly speaking, Infinity, Nan, and undefined are not constants, but are global variables. Bad things could result from attempting to change their values.



continue reserved word

continue statement



constructor function


constructor function prototype function

A constructor is a function that is used to create new objects. A constructor should always be invoked with the new prefix operator. If a constructor is invoked without the new prefix operator, then the this parameter will not be bound to a new object. A constructor has a prototype Function prototype object that is used as the prototype of the new object. See invocation.


copy array


copy object



The correspondence between the variables of a function and the parameters of an inner function.

function frick(n) {
    var result = 1;
    while (n > 1) {
        result *= n;
        n -= 1;
    return result;

function frack(n) {
    return (function (result) {
        while (n > 1) {
            result *= n;
            n -= 1;
        return result;

The functions frick and frack both compute the factorial function. They produce the same result, but frick declares a variable called result, and frack uses the result of an immediate function that has a parameter called result. This demonstrates the correspondence between variables and parameters.

Holds for expressions except for this and arguments. Renaming as that and them. Holds for statements except return, break, and continue, and var and function. Blah.


cos Math function cosine

The Math.cos(radians) function, also known as cosine, takes an angle in radians and returns a number in the range -1...1.

function rotate(polygon, radians) {

// This function takes an array of points, and returns another array
// of points rotated around the origin.

    var cos = Math.cos(radians),
        sin = Math.sin(radians);

    return polygon.map(function (point) {
        return {
            x: point.x * cos - point.y * sin,
            y: point.x * sin + point.y * cos

This is an approximate implemention of Math.cos:

Math.cos = (function () {
    var half_pi = Math.PI / 2;
    return function cos(radians) {
        return Math.sin(radians + half_pi);

See Math function.


See line terminator.


create Object function



Cascading Style Sheets. Blah.

curly brace

See { left curly brace and } right curly brace.



function curry(func) {
    var args = Array.prototype.slice.apply(arguments, [1]);
    return function () {
        return func.apply(null, args.concat(Array.prototype.slice.apply(arguments)));

function add(a, b) {
    return a + b;

var inc = curry(add, 1);