JavaScript assignment operator

Understand the basics of JavaScript assignment operators

Use assignment operator=Assign values to variables:

const a = 2
let b = 2
var c = 2

This operator provides several shortcuts for all arithmetic operators. You can assign the result of the second operand to the first operand.

they are:

  • +=: Additional allocation
  • -=: Subtractive distribution
  • *=: Multiplication distribution
  • /=: Department allocation
  • %=: Remainder allocation
  • **=: Exponentiation distribution

example:

let a = 0
a += 5 //a === 5
a -= 2 //a === 3
a *= 2 //a === 6
a /= 2 //a === 3
a %= 2 //a === 1

To be clear, the above operations are performed one after another, soaThe last is 1, not 0

Download mine for freeJavaScript beginner's manual


More js tutorials: