JavaScript Cheet Sheet

Section 1 - JavaScript Language Fundamentals

1.2 Operators - Example Code

Arithmetic Examples
Demonstrating Addition

document.writeln("5 + 5 = " + (5+5));

Output:
Demonstrating Subtraction

document.writeln("5 - 5 = " + (5-5));

Output:
Demonstrating Multiplication

document.writeln("5 * 5 = " + (5*5));

Output:
Demonstrating Division

document.writeln("5 / 5 = " + (5/5));

Output:
Demonstrating Remainder Operator (%)

document.writeln("5 % 5 = " + (5%5));

Output:
Unary Operator - type of
Output

document.writeln(typeof 38);

document.writeln(typeof true);

document.writeln(typeof undeclaredvariable)

document.writeln(typeof "hello");

var x = {firstName:"John", lastName:"Doe"};
document.writeln(typeof x);

Boolean, Comparison, Logic Operators
Output

document.writeln(5 > 4);

document.writeln(5 < 4);

document.writeln(5 == 5);

document.writeln(5 != 5);

document.writeln(5 === 5);

document.writeln(5 === "5");

document.writeln(5 == "5");

document.writeln(5 !== 5);

document.writeln((5 > 4) && (2 < 3));

document.writeln((5 > 4) && (2 < 1));

document.writeln((5 > 4) || (2 < 1));