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

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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: