-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.js
More file actions
35 lines (27 loc) · 975 Bytes
/
Operators.js
File metadata and controls
35 lines (27 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Sample program to demonstrate various operators
by Jeremy Gallen */
// Declare variables
var a = 32, b = 2, int4 = 4, bit1 = 8, bit2 = 2, str = "4";
// Demonstrate shift operators
console.log("a<<b: " + (a<<b));
console.log("a>>b: " + (a>>b));
console.log("b<<a: " + (b<<a));
console.log("b>>a: " + (b>>a));
// Print break
console.log();
// Demonstrate relational operators
console.log("int4 == str: " + (int4==str));
console.log("int4 === str: " + (int4===str));
// Print break
console.log();
// Demonstrate bitwise operators
console.log("bit1&bit2: " + (bit1&bit2));
console.log("bit1|bit2: " + (bit1|bit2));
console.log("bit1^bit2: " + (bit1^bit2));
console.log("~bit1: " + (~bit1));
console.log("~bit2: " + (~bit2));
// Print break
console.log();
// Demonstrate ternary operator
(a>b)?console.log("a is greater than b"):console.log("a is less than b");
(b>a)?console.log("b is greater than a"):console.log("b is less than a");