Data Type | Examples |
Number | 1 1024 18.0 3.14159 1.024e3 |
String | "" "foo" "2 words" |
Boolean | true false |
Operator | Name | Data Types | Expressions | Values |
+ | Addition or Concatenation |
Number String |
3 + 1 4 + 7.432 "foo" + "bar" |
4 11.432 "foobar" |
- | Subtraction | Number | 7 - 2 5 - 3.359 |
5 1.641 |
* | Multiplication | Number | 2 * 5 10 * 9.773 |
10 97.73 |
/ | Division | Number | 10 / 4 2.5 / 8 |
2.5 0.3125 |
% | Remainder | Number | 10 % 4 2 % 0.75 |
2 0.5 |
&& | AND | Boolean | true && true true && false false && true false && false |
true false false false |
|| | OR | Boolean | true || true true || false false || true false || false |
true true true false |
! | NOT | Boolean | !true !false |
false true |
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" |
Statement Name | General Form | Examples |
Comment | ||
Assignment Statement |
| |
If-Then Statement |
|
|
While Loop |
|
"); count = count + 1; } |
Function | Examples | Result |
Square Root | x = Math.sqrt(9); | x == 3 |
Absolute Value | x = Math.abs(-23); y = Math.abs(99); |
x == 23 y == 99 |
Maximum | x = Math.max(3,14); | x == 14 |
Minimum | x = Math.min(3,14); | x == 3 |
Power | x = Math.pow(2,3); | x == 8 |
Floor | x = Math.floor(3.14159); y = Math.floor(4.5623); |
x == 3 y == 4 |
Ceiling | x = Math.ceil(3.14159); y = Math.ceil(4.5623); |
x == 4 y == 5 |
Round | x = Math.round(3.14159); y = Math.round(4.5623); |
x == 3 y == 5 |
ParseFloat | x = parseFloat("12.8"); y = parseFloat("ABC"); |
x == 12.8 y == NaN |
Prompt |
yourName = prompt("Please enter your name","Anonymous");
The following dialog box will appear, and yourName will be assigned the value that is entered in the text field. | |
Write | document.write("Howdy"); document.write(2+3); |
displays "Howdy" displays 5 |
Action | General Form | Examples |
Function Definition |
|
|
Function Call |
|
|