JSDB     Home    License    Download    Tutorial    Reference    Projects    Feedback    History

Getting started with JavaScript

What you type is in boldface.

Math

js>1 + 1
2
js>1 + 5 * 5
26
js>(1 + 5) * 5
30
js>Math.pow(5,2)
25
js>Math.log(10)
2.302585092994046
js>Math.PI
3.141592653589793
js>Math.E
2.718281828459045
js>Math.cos(Math.PI / 3)
0.5000000000000001
js>Math.cos(Math.PI / 3).toFixed(3)
0.500
js>Math.min(8 + 4 * 2, (8 + 4) * 2);
16
js>Math.sqrt(8*8);
8

Other Math functions are Math.abs(x), Math.acos(x), Math.asin(x), Math.atan(x), Math.atan2(x,y), Math.ceil(x), Math.cos(x), Math.exp(x), Math.floor(x), Math.log(x), Math.max(x), Math.min(x), Math.pow(x,y), Math.random(), Math.round(x), Math.sin(x), Math.sqrt(x), Math.tan(x)

Logic

js>1 < 4
true
js>1 > 4
false
js>true && false
false
js>true || false
true
js>3 == 4
false
js>3 != 4
true
js>!true
false

More JS Logic

Variables

js>var a
js>a = 5
5
js>a = "Hello, World!"
Hello, World!
js>b = [a,2,'three',null,5]
Hello, World!,2,three,,5
js>b[2]
three
js>

Functions

js>function sum(a,b) 
2:{
3: return a+b;
4:}
js>function info(obj)
2:{
3: print(obj.name + ' ' + obj.age);
4:}

Objects

js>c = new Object
[object Object]
js>c.name = 'Alice'
Alice
js>c.age = 30
30
js>info(c)
Alice 30
js>d = {name: 'Bob', age: 35}
[object Object]
js>info(d)
Bob 35

Next

The JSDB tutorial