Get in touch
or send us a question?
CONTACT

[Node.js Tutorials for Beginners] – Unit 4: Operator in Node.js

thumbnail

Table of Contents

1. Arithmetic Operators

2. Comparison Operators

3. Logical Operators

4. Assignment Operators

1. Arithmetic Operators

Assume variable A holds 10 and variable B holds 20

Example:

var a = 10

var b = 20

console.log(“a + b = ” + (a + b))

console.log(“a + b = ” + (a – b))

console.log(“a * b = ” + (a * b))

console.log(“a / b = ” + (a / b))

console.log(” ++a = ” + (++a))

console.log(“–a = ” + (–a))

Output:

2. Comparison Operators

Assume variable A holds 10 and variable B holds 20

Example:

var a = 10

var b = 20

console.log(“a > b is ” + (a > b))

console.log(“a < b is ” + (a < b))

console.log(“a == b is ” + (a == b))

console.log(“a != b is ” + (a != b))

console.log(“a >= b is ” + (a >= b))

console.log(“a <= b is ” + (a <= b))

Output:

3. Logical Operators

Assume variable A holds 10 and variable B holds 20

Example:

a = true;

b = false;

console.log(“a AND b => ” + (a && b));

console.log(“a OR b => ” + (a || b));

console.log(“a NOT b => ” + !(a && b));

Output:

4. Assignment Operators

Example:

var a = 10;

var b = 20;

console.log(“Value of a = ” + (a = b))

console.log(“Value of a = ” + (a += b))

console.log(“Value of a = ” + (a -= b))

console.log(“Value of a = ” + (a *= b))

console.log(“Value of a = ” + (a /= b))

console.log(“Value of a = ” + (a %= b))

Output:

Thank you for reading!