Main MenuJavascript command
Result
document.write ("1. Hello world");
// simple output
document.write ("2. 2 + 3 = ",2+3);
// simple calculator
document.write ("3. √2 = ", Math.sqrt(2), " also ",Math.SQRT2);
// square root
document.write ("4. 2"+"0.5".sup()+" = ", Math.pow(2,0.5));
// Powers
var D2R = Math.PI/180;
document.write ("5. Sin(60°) = ", Math.sin(60*D2R));
// Trig functions
document.write ("6. Log(2) = ", Math.log(2)/Math.log(10));
// Log is the natural log LN
var x = 3, y = 5; z = x + y;
document.write ("7. x = ", x, "; y = ", y, "; z = x + y = ", z);
// variable assignment
document.write ("8. ");
if (z>6) { document.write ("z is bigger than 6")} else {document.write ("It ain't")};
// if else
document.write ("9. x = ", x=2 );
while (x<6) {x = x+1; document.write ( ", ", x )}
document.write ("<br>");
// while
document.write ("10. ") for ( x = 2; x<=6; x++ )
// x++ is the same as x += 1 which is the same as x = x + 1
document.write ((x==2 ? "x = " : ", "), x ); document.write ("<br>");
// for
document.write ("11. x = ")
for ( x = 2, document.write (x); x<6; document.write ( ", ", ++x)); document.write("<br>");
document.write ("12. ")
var days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
d = new Date(); year = String(d.getFullYear()); day = d.getDay(); month = d.getMonth();
document.write("Today, ", month+1, "/", d.getDate(), "/", year.substr(2,2),", ");
document.write(" is ", days[day], ", ",months[month]," ",d.getDate(),", ",year,"<br>");
document.write ("13. x = ", x=2 );
do {x = x+1; document.write ( ", ", x )} while (x<6); document.write ("<br>");
// do .. while
. . . . Operators . . . . . . . . . . . .Properties . . . . . . . . . . . . . . . . . . . . Methods . . . . . . . . . . . .
Arithmetic
+   =  ++ +=  -  -- -=  /  %
Math.E
Euler's constant and the base of natural logarithms (approximately 2.7183)
Math.abs (  a  ) 
the absolute value of a
Math.floor (  a  ) 
integer closest to and not greater than a
Assignment
=  += -= *= /= %= <<=
>>= >>>= &= ^= |=
Math.LN10
the natural logarithm of 10, (approximately 2.3026).
Math.acos (  a  ) 
arc cosine of a
Math.log (  a  ) 
log of a base e
String
+
Math.LN2
the natural logarithm of 2, (approximately 0.6931).
Math.asin (  a  ) 
arc sine of a
Math.max (  a , b  ) 
the maximum of a and b
Backslash
\' \" \\ \b \f \n \r \t
Math.LOG10E
the base 10 logarithm of E (approximately 0.4343)
Math.atan (  a  ) 
arc tangent of a
Math.min (  a , b  ) 
the minimum of a and b
Bitwise
&   |  ^ (XOR)  ~  << >> >>>
Math.LOG2E
the base 2 logarithm of E (approximately 1.4427).
Math.atan2 (  a , b  ) 
arc tangent of a/b
Math.pow (  a , b  ) 
a to the power b
Comparison
==   !=   ===   !==   >   >=   <   <=  
Math.PI
the ratio of the circumference of a circle to its diameter (approximately 3.1416)
Math.ceil (  a  ) 
integer closest to a and not less than a
Math.random( )
pseudo random number in the range 0 to 1
Logical
&&   ||  
Math.SQRT1_2
the value of 1 divided by the square root of 2 (approximately 0.7071).
Math.cos (  a  ) 
cosine of a
Math.round (  a  ) 
integer closest to a
Math.SQRT2
the square root of 2 (approximately 1.4142)
Math.exp (  a  ) 
exp(a)= e^a
Math.sin (  a  ) 
sine of a
Special
(a==b ? "is" : "ain't")
for (var i=0 , j=0; i<3; i++ , j++)Math.tan (  a  ) 
tangent of a
Math.sqrt (  a  ) 
square root of a