Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

JavaScript Assignment Operators

Notes:

JavaScript Assignment Operators

Assignment Operator: is used to assign a value to variable or a constant.
= : Assignment Operator

Short Hand Assignment (SHA): AA (Arithmetic Assignment)
+=
-=
*=
/=
%=

Example code:
const PI = 3.142;
document.write("PI=",PI); // PI=3.142

var a = 10;
document.write("a=",a); // a=10
a = 20;
document.write("a=",a); // a=20
a += 10; // a = a + 10;
document.write("a=",a); // a=30
a-=10; // a = a - 10;
document.write("a=",a); // a=20
a*=2; // a = a * 2;
document.write("a=",a); // a=40
a/=2; // a = a / 2;
document.write("a=",a); // a=20
a%=2; // a = a % 2;
document.write("a=",a); // a=0
a += 10;
document.write("a=",a); // a=10

Interview Questions: