Javascript Function Reference
(thanks to http://www.javascriptkit.com/jsref)
- Arithmetic Operators
- Comparison Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Other Operators
- Math Functions and Properties
- String Functions and Properties
1. Arithmetic Operators
| Operator |
Description |
Examples |
| + (add) |
Adds numeric operands or concatenates
two or more strings. |
| x+y | "Me"+" You" result: "Me You" |
|
| - (subtract) |
Subtracts numeric operands. |
x-7 |
| * (multiply) |
Multiplies numeric operands. |
5*2 |
| / (divide) |
Divides numeric operands. |
y/x |
| % (modulo) |
Returns the remainder when the first
operand is divided by the second operand. |
7%2 result: 1 |
| ++ (increment) |
Increments the operand by 1. Note the
following two possible behaviors:- If operator is used before
operand (ie: ++x), it increments the operand and evaluates to the
incremented value.
- If operator is used following operand (ie: x++), it increments
the operand but evaluates to the unincremented value.
|
Using x=2 for each example below:
x++ result: x=3
y= ++x result: y=3, x=3
y= x++ result: y=2, x=3
|
| -- (decrement) |
Decrements the operand by 1. Note the
following two possible behaviors:- If operator is used before
operand (ie: --x), it increments the operand and evaluates to the
incremented value.
- If operator is used following operand (ie: x--), it increments
the operand but evaluates to the unincremented value.
| x-- |
Note: With all of the Operators above (except Addition (+)), if an
operand used is non numeric, operator will attempt to convert it to a number
first.
2. Comparison Operators
| Operator |
Description |
Examples |
| == |
Tests for equality in value between two
operands. |
3==8
returns false |
| === |
Tests for equality between two operands
both in terms of value and type. Supported in JavaScript 1.3+ |
Using x=3 and y="3":
x == y result: true
x === y result: false |
| < |
Less than. |
x<=y |
| <= |
Less than or equal to. |
5<=x |
| > |
Greater than. |
y>4 |
| >= |
Greater than or equal. |
x>=y |
3. Assignment Operators
| Operator |
Example |
Equivalent to: |
| = |
y=x+3 |
n/a |
| += |
x+=3 |
x=x+3 |
| -= |
x-=y |
x=x-y |
| *= |
x*=y |
x=x*y |
| /= |
x/=y |
x=x/y |
| %= |
x%=y |
x=x%y |
4. Logical Operators
| Operator |
Description |
Examples |
| && (AND) |
Logical AND. |
(x<3 && y<=5) |
| || (OR) |
Logical OR |
(x<3 || y<=5) |
| ! (NOT) |
Logical NOT. |
!(x>3) |
5. Bitwise Operators
| Operator |
Description |
| & |
Bitwise AND. |
| | |
Bitwise OR |
| ^ |
Bitwise XOR. |
| << |
Shift left. |
| >> |
Shift right. |
| >>> |
Shift right, zero fill. |
6. Other Operators
| Operator |
Description |
| ?: |
"?:", or the Conditional Operator, is a
shorthand method for constructing an evaluation, and executing two
different assignments depending on the result. The syntax is:
condition ? iftrue : iffalse
For example: y=-1
x=(y<0)? 5: 10 result: x = "5" |
| typeof |
The "typeof" operator allows you to
probe the data type of its operand, such as whether a variable is
string, numeric, or even undefined.
Here are some of the possible return values:
| Evaluates to |
Indicates |
| "number" |
Operand is a number |
| "string" |
Operand is a string |
| "boolean" |
Operand is a Boolean |
| "object" |
Operand is an object |
| null |
Operand is null. |
| "undefined" |
Operand is not defined. |
|
| instanceof |
Returns a Boolean value indicating
whether the left hand operand is of the type specified in the right
hand operand. For example: var today=new Date()
alert(today instanceof Number) //alerts false, since today is not a
Number. |
| delete |
Deletes a custom object
property, method, or array element. For example:
var mycar=new Object()
mycar.color="red"
delete mycar.color //deletes the property "color" |
7. Math Constants and Functions
Note:
Normal Javascript use requires the Math prefix (Math.propertyname or Math.functionname()). Within the Objectsheet, this prefix is not necessary.
| Properties |
Description |
| E |
The constant of E, the base of natural
logarithms. |
| LN2 |
The natural logarithm of 2. |
| LN10 |
The natural logarithm of 10. |
| LOG2E |
Base 2 logarithm of E. |
| LOG10E |
Base 10 logarithm of E. |
| PI |
Returns PI. |
| SQRT1_2 |
Square root of 1/2. |
| SQRT2 |
Square root of 2. |
| Methods |
Description |
| abs(x) |
Returns absolute value of
x. |
| acos(x) |
Returns arc cosine of x
in radians. |
| asin(x) |
Returns arc sine of x in
radians. |
| atan(x) |
Returns arc tan of x in
radians. |
| atan2(y, x) |
Counterclockwise angle
between x axis and point (x,y). |
| ceil(x) |
Returns the smallest
integer greater than or equal to x. (round up). |
| cos(x) |
Returns cosine of x,
where x is in radians. |
| exp(x) |
Returns ex |
| floor(x) |
Returns the largest integer less than or equal to x. (round down) |
| log(x) |
Returns the natural logarithm (base E) of x. |
| max(a, b) |
Returns the larger of a
and b. |
| min(a, b) |
Returns the lesser of a
and b. |
| pow(x, y) |
Returns Xy |
| random() |
Returns a pseudorandom
number between 0 and 1. |
| round(x) |
Rounds x up or down to
the nearest integer. It rounds .5 up. |
| sin(x) |
Returns the Sin of x,
where x is in radians. |
| sqrt(x) |
Returns the square root
of x. |
| tan(x) |
Returns the Tan of x,
where x is in radians. |
8. String Properties
| Properties |
Description |
| length |
Returns the length of the string (# of
characters). |
| prototype |
Use this property to attach additional
properties and/or methods that get reflected in all instances of the
String. |
Methods
Note:
"[]" surrounding a parameter below means the parameter is optional.
| Methods |
Description |
| anchor(name) |
Returns the string with
the tag <A name="name"> surrounding it. |
| big() |
Returns the string with
the tag <BIG> surrounding it. |
| blink() |
Returns the string with
the tag <BLINK> surrounding it. |
| bold() |
Returns the string with
the tag <B> surrounding it. |
| fixed() |
Returns the string with
the tag <TT> surrounding it. |
| fontcolor(color) |
Returns the string with
the tag <FONT color="color"> surrounding it. |
| fontsize(size) |
Returns the string with
the tag <FONT size="size"> surrounding it. |
| italics() |
Returns the string with
the tag <I> surrounding it. |
| link(url) |
Returns the string with
the tag <A href="url"> surrounding it. |
| small() |
Returns the string with
the tag <SMALL> surrounding it. |
| strike() |
Returns the string with
the tag <STRIKE> surrounding it. |
| sub() |
Returns the string with
the tag <SUB> surrounding it. |
| sup() |
Returns the string with
the tag <SUP> surrounding it. |
| charAt(x) |
Returns the character at
the "x" position within the string. |
| charCodeAt(x) |
Returns the Unicode value
of the character at position "x" within the string. |
| concat(v1, v2,...) |
Combines one or more
strings (arguments v1, v2 etc) into the existing one and returns the
combined string. Original string is not modified. |
| fromCharCode(c1, c2,...) |
Returns a string created
by using the specified sequence of Unicode values (arguments c1, c2
etc). Method of String object, not String instance. For example:
String.fromCharCode(). |
| indexOf(substr, [start]) |
Searches and (if found)
returns the index number of the searched character or substring
within the string. If not found, -1 is returned.
"Start" is an optional argument specifying the position within
string to begin the search. Default is 0. |
| lastIndexOf(substr,
[start]) |
Searches and (if found)
returns the index number of the searched character or substring
within the string. Searches the string from end to beginning. If not
found, -1 is returned. "Start" is an optional argument specifying
the position within string to begin the search. Default is
string.length-1. |
| match(regexp) |
Executes a search for a
match within a string based on a regular expression. It returns an
array of information or null if no match is found. |
| replace( regexp,
replacetext) |
Searches and replaces the
regular expression portion (match) with the replaced text instead. |
| search(regexp) |
Tests for a match in a
string. It returns the index of the match, or -1 if not found. |
| slice(start, [end]) |
Returns a substring of
the string based on the "start" and "end" index arguments,
NOT including the "end" index itself. "End" is
optional, and if none is specified, the slice includes all
characters from "start" to end of string. |
| split(delimiter,
[limit]) |
Splits a string into many
according to the specified delimiter, and returns an array
containing each element. The optional "limit" is an integer that
lets you specify the maximum number of elements to return. |
| substr(start, [length]) |
Returns the characters in a string beginning at "start" and through
the specified number of characters, "length". "Length" is
optional, and if omitted, up to the end of the string is assumed. |
| substring(from, [to]) |
Returns the characters in a string between "from" and "to"
indexes, NOT including "to" inself. "To" is optional, and if
omitted, up to the end of the string is assumed. |
| toLowerCase() |
Returns the string with
all of its characters converted to lowercase. |
| toUpperCase() |
Returns the string with
all of its characters converted to uppercase. |
|