...

>

Operators & Expressions in JS

Operators & Expressions in JS

This lesson lists the commonly used JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical and string.

Operators

JavaScript operators can be categorized into two main categories i.e., Unary and Binary operators. Unary takes only one operand whereas binary takes two.

1. Binary Operators

Binary operators can further be divided into following types:

  • Arithmetic Operators (+,,,/+, -, *, /)
Javascript (babel-node)
//Arithmetic Operators
console.log("****Arithmetic Operators****\n")
console.log("2 + 3 = " + (2 + 3))
console.log("2 - 3 = " + (2 - 3))
console.log("2 * 3 = " + (2 * 3))
console.log("6 / 3 = " + (6 / 3))
console.log("7 / 3 = " + (7 / 3))
  • Assignment Operators (=, +=, -=, *=, /=)
Javascript (babel-node)
//Assignment Operators
console.log("\n****Assignment Operators****\n")
var x = 3;
console.log("x = " + x)
console.log("x += 1 gives x = " + (x+=1)) // adds 1 = value of x=4
console.log("x -= 1 gives x = " + (x-=1)) // subtracts 1 = value of x=3
console.log("x *= 3 gives x = " + (x*=3)) // multiplies 3 with x = value of x=9
console.log("x /= 3 gives x = " + (x/=3)) // Divides 3 with x = value of x=3
...