MCS 170 - Spring 2005

JavaScript Quick Reference

(from Dave Reed's Course at Dickinson College - 2004)

Data Types:

Variables:

Operators:

    Operator Name Data Types Examples Result
    = Assignment Number
    String
    Boolean
    x = 3;
    y = 7.654;
    Str = "foo";
    flag = true;
    x == 3
    y == 7.654
    Str == "foo"
    flag == true
    + Addition or
    Concatenation
    Number
    String
    x = 4 + 3;
    y = x + 7.432;
    Str = "foo" + "bar";
    x == 7
    y == 14.432
    Str == "foobar"
    - Subtraction Number x = 7 - 2;
    y = x - 3.359;
    w == 5
    y == 1.641
    * Multiplication Number x = 2 * 5;
    y = x * 9.773;
    x == 10
    y == 97.73
    / Division Number x = 10 / 4;
    y = x / 8;
    x == 2.5
    y == .3125
    % Remainder1 Number x = 10 % 4;
    y = x % .75;
    x == 2
    y == .5
    && AND Boolean flag = true;
    D = true && flag;
    D = D && false;
    flag == true
    D == true
    D == false
    || OR Boolean flag = true;
    D = flag || true;
    D = false || D;
    flag == true
    D == true
    D == false
    ! NOT Boolean D = !true;
    D = !D;
    D == false
    D == true
    1. The Remainder operator is often referred to as the Modulo operator.

Comparison:

    Operator Name Data Types Examples
    == Equality Number
    String
    Boolean
    3 == 3
    "test" == "test"
    false == false
    != Inequality Number
    String
    Boolean
    12 != 39
    "foo" != "bar"
    false != true
    < Less Than Number
    String1
    2 < 3.1415
    "a" < "b"
    <= Less Than or Equal Number
    String1
    17 <= 17
    "ABC" <= "ABD"
    > Greater Than Number
    String1
    12 > -4
    "foo" > "bar"
    >= Greater Than or Equal Number
    String1
    3.99 >= 3.98
    "fool" >= "foo"
    1. Strings follow standard dictionary ordering, i.e.,
        "A" < "B" < ... < "Z" < "a" < "b" ... < "z"
        "a" < "aa" < ... < "ab" < "aba" < ... < "b"

Statements:

Built In Functions:

User Defined Functions