- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Assignment Operators in JavaScript?
Using Assignment Operators, you can assign a value to a variable. JavaScript supports the following assignment operators −
Sr.No | Operator and Description |
---|---|
1 | = (Simple Assignment ) Assigns values from the right side operand to the left side operand Ex: C = A + B will assign the value of A + B into C |
2 | += (Add and Assignment) It adds the right operand to the left operand and assigns the result to the left operand. Ex: C += A is equivalent to C = C + A |
3 | −= (Subtract and Assignment) It subtracts the right operand from the left operand and assigns the result to the left operand. Ex: C -= A is equivalent to C = C – A |
4 | *= (Multiply and Assignment) It multiplies the right operand with the left operand and assigns the result to the left operand. Ex: C *= A is equivalent to C = C * A |
5 | /= (Divide and Assignment) It divides the left operand with the right operand and assigns the result to the left operand. Ex: C /= A is equivalent to C = C / A |
6 | %= (Modules and Assignment) It takes the modulus using two operands and assigns the result to the left operand. Ex: C %= A is equivalent to C = C % A |
Example
Try the following code to implement assignment operator in JavaScript −
<html> <body> <script> <!-- var a = 33; var b = 10; var linebreak = "<br />"; document.write("Value of a => (a = b) => "); result = (a = b); document.write(result); document.write(linebreak); document.write("Value of a => (a += b) => "); result = (a += b); document.write(result); document.write(linebreak); document.write("Value of a => (a -= b) => "); result = (a -= b); document.write(result); document.write(linebreak); document.write("Value of a => (a *= b) => "); result = (a *= b); document.write(result); document.write(linebreak); document.write("Value of a => (a /= b) => "); result = (a /= b); document.write(result); document.write(linebreak); document.write("Value of a => (a %= b) => "); result = (a %= b); document.write(result); document.write(linebreak); //--> </script> <p>Set the variables to different values and different operators and then try...</p> </body> </html>
- Related Articles
- What are assignment operators in C#?
- What are the assignment operators in Java?
- What are different assignment operators types in Python?
- Assignment Operators in C++
- Java Assignment Operators
- Python Assignment Operators
- Perl Assignment Operators
- Compound Assignment Operators in C++
- Compound assignment operators in C#
- Assignment operators in Dart Programming
- What are operators in JavaScript?
- Compound assignment operators in Java\n
- What are JavaScript Operators
- What is the difference between = and: = assignment operators?
- What are Arithmetic Operators in JavaScript?

Advertisements