Shift Assignment Operators
Bitwise assignment operators, logical assignment operators, the = operator.
The Simple Assignment Operator assigns a value to a variable.
Simple Assignment Examples
The += operator.
The Addition Assignment Operator adds a value to a variable.
Addition Assignment Examples
The -= operator.
The Subtraction Assignment Operator subtracts a value from a variable.
Subtraction Assignment Example
The *= operator.
The Multiplication Assignment Operator multiplies a variable.
Multiplication Assignment Example
The **= operator.
The Exponentiation Assignment Operator raises a variable to the power of the operand.
Exponentiation Assignment Example
The /= operator.
The Division Assignment Operator divides a variable.
Division Assignment Example
The %= operator.
The Remainder Assignment Operator assigns a remainder to a variable.
Remainder Assignment Example
The <<= Operator
The Left Shift Assignment Operator left shifts a variable.
Left Shift Assignment Example
The >>= operator.
The Right Shift Assignment Operator right shifts a variable (signed).
Right Shift Assignment Example
The >>>= operator.
The Unsigned Right Shift Assignment Operator right shifts a variable (unsigned).
Unsigned Right Shift Assignment Example
The &= operator.
The Bitwise AND Assignment Operator does a bitwise AND operation on two operands and assigns the result to the the variable.
Bitwise AND Assignment Example
The |= operator.
The Bitwise OR Assignment Operator does a bitwise OR operation on two operands and assigns the result to the variable.
Bitwise OR Assignment Example
The ^= operator.
The Bitwise XOR Assignment Operator does a bitwise XOR operation on two operands and assigns the result to the variable.
Bitwise XOR Assignment Example
The &&= operator.
The Logical AND assignment operator is used between two values.
If the first value is true, the second value is assigned.
Logical AND Assignment Example
The &&= operator is an ES2020 feature .
The ||= Operator
The Logical OR assignment operator is used between two values.
If the first value is false, the second value is assigned.
Logical OR Assignment Example
The ||= operator is an ES2020 feature .
The ??= Operator
The Nullish coalescing assignment operator is used between two values.
If the first value is undefined or null, the second value is assigned.
Nullish Coalescing Assignment Example
The ??= operator is an ES2020 feature .
Test Yourself With Exercises
Use the correct assignment operator that will result in x being 15 (same as x = x + y ).
Start the Exercise
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top references, top examples, get certified.
- Skip to main content
- Skip to search
- Skip to select language
- Get MDN Plus
- English (US)
The assignment ( = ) operator is used to assign a value to a variable. The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables.
Simple assignment and chaining
Value of assignment expressions.
The assignment expression itself evaluates to the value of the right-hand side, so you can log the value and assign to a variable at the same time.
- Assignment operators in the JS guide
- Destructuring assignment
- Android App Development (Live)
- Data Science (Live)
- DSA for Interview Preparation
- DSA Live for Working Professionals
- DSA Self-paced in C++/Java
- DSA Self-paced in Python
- DSA Self-paced in C
- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- Explore More Live Courses
- Interview Preparation Course
- GATE CS & IT 2024
- Data Structure & Algorithm-Self Paced(C++/JAVA)
- Data Structures & Algorithms in Python
- Explore More Self-Paced Courses
- C++ Programming - Beginner to Advanced
- Java Programming - Beginner to Advanced
- C Programming - Beginner to Advanced
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- Android App Development with Kotlin(Live)
- Python Backend Development with Django(Live)
- Complete Data Science Program(Live)
- Mastering Data Analytics
- DevOps Engineering - Planning to Production
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Generic Tree
- Binary Tree
- Binary Search Tree
- Red Black Tree
- All Tree Data Structures
- Advanced Data Structure
- All Data Structures
- Design and Analysis of Algorithms
- Asymptotic Analysis
- Worst, Average and Best Cases
- Asymptotic Notations
- Little o and little omega notations
- Lower and Upper Bound Theory
- Analysis of Loops
- Solving Recurrences
- Amortized Analysis
- What does 'Space Complexity' mean ?
- Pseudo-polynomial Algorithms
- Polynomial Time Approximation Scheme
- A Time Complexity Question
- Linear Search
- Binary Search
- All Searching Algorithms
- Selection Sort
- Bubble Sort
- Insertion Sort
- Counting Sort
- Bucket Sort
- All Sorting Algorithms
- Greedy Algorithms
- Dynamic Programming
- Graph Algorithms
- Pattern Searching
- Divide and Conquer
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Branch and Bound
- All Algorithms
- What is System Design
- Monolithic and Distributed SD
- Scalability in SD
- Databases in SD
- High Level Design or HLD
- Low Level Design or LLD
- Complete System Design Tutorial
- Factory Pattern
- Observer Pattern
- Singleton Design Pattern
- Decorator Pattern
- Strategy Pattern
- Adapter Pattern
- Command Pattern
- Iterator Pattern
- Prototype Design Pattern
- All Design Patterns
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Multiple Choice Quizzes
- Aptitude for Placements
- Go Language
- Tailwind CSS
- Foundation CSS
- Materialize CSS
- Semantic UI
- Angular PrimeNG
- Angular ngx Bootstrap
- jQuery Mobile
- jQuery EasyUI
- React Bootstrap
- React Rebass
- React Desktop
- React Suite
- ReactJS Evergreen
- ReactJS Reactstrap
- English Grammar
- School Programming
- Number System
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 11 Syllabus
- Class 12 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Formulas
- Class 9 Formulas
- Class 10 Formulas
- Class 11 Formulas
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- Class 7 SS Syllabus
- Class 8 SS Syllabus
- Class 9 SS Syllabus
- Class 10 SS Syllabus
- Class 7 Notes
- History Class 7
- History Class 8
- History Class 9
- Geo. Class 7
- Geo. Class 8
- Geo. Class 9
- Civics Class 7
- Civics Class 8
- Business Studies (Class 11th)
- Microeconomics (Class 11th)
- Statistics for Economics (Class 11th)
- Business Studies (Class 12th)
- Accountancy (Class 12th)
- Macroeconomics (Class 12th)
- Political Science
- Machine Learning
- Data Science
- Microsoft Azure Tutorial
- Google Cloud Platform
- Operating System
- Computer Networks
- Computer Organization and Architecture
- Theory of Computation
- Compiler Design
- Digital Logic
- Software Engineering
- GATE 2024 Live Course
- GATE Computer Science Notes
- Last Minute Notes
- GATE CS Solved Papers
- GATE CS Original Papers and Official Keys
- GATE CS 2023 Syllabus
- Important Topics for GATE CS
- GATE 2023 Important Dates
- ISRO CS Original Papers and Official Keys
- ISRO CS Solved Papers
- ISRO CS Syllabus for Scientist/Engineer Exam
- UGC NET CS Notes Paper II
- UGC NET CS Notes Paper III
- UGC NET CS Solved Papers
- HTML Cheat Sheet
- CSS Cheat Sheet
- Bootstrap Cheat Sheet
- JS Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro Coding Sheet
- Infosys Coding Sheet
- TCS Coding Sheet
- Cognizant Coding Sheet
- HCL Coding Sheet
- FAANG Coding Sheet
- Love Babbar Sheet
- Mass Recruiter Sheet
- Product-Based Coding Sheet
- Company-Wise Preparation Sheet
- Array Sheet
- String Sheet
- Graph Sheet
- Geography Notes
- Modern Indian History Notes
- Medieval Indian History Notes
- Ancient Indian History Notes
- Complete History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- Government Schemes (Updated)
- UPSC Previous Year Papers
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Student Chapter
- Geek on the Top
- SSC CGL Syllabus
- General Studies
- Subjectwise Practice Papers
- Previous Year Papers
- SBI Clerk Syllabus
- General Awareness
- Quantitative Aptitude
- Reasoning Ability
- SBI Clerk Practice Papers
- SBI PO Syllabus
- SBI PO Practice Papers
- IBPS PO 2022 Syllabus
- English Notes
- Reasoning Notes
- Mock Question Papers
- IBPS Clerk Syllabus
- Corporate Hiring Solutions
- Apply through Jobathon
- Apply for a Job
- All DSA Problems
- Problem of the Day
- GFG SDE Sheet
- Top 50 Array Problems
- Top 50 String Problems
- Top 50 Tree Problems
- Top 50 Graph Problems
- Top 50 DP Problems
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- Web Development
- Write an Interview Experience
- Write an Admission Experience
- Displaying XML Using CSS
- HTML vs XML
- Difference between JSON and XML
- XML | Basics
- XML | Syntax
- XML | Elements
- XML | Attributes
- Displaying XML Using XSLT
- File uploading in React.js
- Hide elements in HTML using display property
The simple assignment operator is used to assign a value to a variable. The assignment operation evaluates the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables. See the example.
Assignment Operators List: There are so many assignment operators as shown in the table with the description.
Below we have described each operators with a example code
Addition Assignment: This operator adds the value to the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible. In case of concatenation then we use the string as an operand.
Subtraction Assignment: This operator subtracts the value of the right operand from a variable and assigns the result to the variable.
Multiplication Assignment: This operator multiplies a variable by the value of the right operand and assigns the result to the variable.
Division Assignment: This operator divides a variable by the value of the right operand and assigns the result to the variable.
Remainder Assignment : This operator divides a variable by the value of the right operand and assigns the remainder to the variable.
Exponentiation Assignment: This operator raises the value of a variable to the power of the right operand.
Left Shift Assignment: This operator moves the specified amount of bits to the left and assigns the result to the variable.
Right Shift Assignment: This operator moves the specified amount of bits to the right and assigns the result to the variable.
Bitwise AND Assignment: This operator uses the binary representation of both operands, does a bitwise AND operation on them, and assigns the result to the variable.
Bitwise OR Assignment: This operator uses the binary representation of both operands, does a bitwise OR operation on them, and assigns the result to the variable.
Bitwise XOR Assignment: This operator uses the binary representation of both operands, does a bitwise XOR operation on them, and assigns the result to the variable.
Please Login to comment...
- Web Technologies
Full Stack Development with React & Node JS - Live
Improve your coding skills with practice.
An assignment operator ( = ) assigns a value to a variable. The syntax of the assignment operator is as follows:
The following example declares the counter variable and initializes its value to zero:
The following example increases the counter variable by one and assigns the result to the counter variable:
To make the code more concise, you can use the += operator like this:
In this syntax, you don’t have to repeat the counter variable twice in the assignment.
The following table illustrates assignment operators that are shorthand for another operator and the assignment:
If you want to assign a single value to multiple variables, you can chain the assignment operators. For example:
- Use the assignment operator ( = ) to assign a value to a variable.
- Chain the assignment operators if you want to assign a single value to multiple variables.
Learn coding interactively.
Popular tutorials, popular examples, reference materials, learn python interactively, js introduction.
- Getting Started
- JS Variables & Constants
- JS console.log
- JS Type Conversions
JS Control Flow
- JS Comparison Operators
- Variable Scope
- JS Multidimensional Array
Exceptions and Modules
- Destructuring Assignment
- Iterators and Iterables
- What is an Operator?
Here + is an operator that performs addition, and 2 and 3 are operands.
Here is a list of different operators you will learn in this tutorial.
- Assignment Operators
- Arithmetic Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
- String Operators
- Other Operators
Assignment operators are used to assign values to variables. For example,
Here, the = operator is used to assign value 5 to variable x .
Here's a list of commonly used assignment operators:
Note: The commonly used assignment operator is = . You will understand other assignment operators such as += , -= , *= etc. once we learn arithmetic operators.
Arithmetic operators are used to perform arithmetic calculations . For example,
Here, the + operator is used to add two operands.
Visit ++ and -- operator to learn more.
Comparison operators compare two values and return a boolean value, either true or false . For example,
Here, the comparison operator > is used to compare whether a is greater than b .
Comparison operators are used in decision-making and loops. You will learn about the use of comparison operators in detail in later tutorials.
Logical operators perform logical operations and return a boolean value, either true or false . For example,
Here, && is the logical operator AND . Since both x < 6 and y < 5 are true , the result is true .
Logical operators are used in decision making and loops. You will learn about the use of logical operators in detail in later tutorials.
Bitwise operators perform operations on binary representations of numbers.
Note: When + is used with strings, it performs concatenation. However, when + is used with numbers, it performs addition.
Table of Contents
Sorry about that.
The assignment operators are used to assign value based on the right operand to its left operand.
The left operand must be a variable while the right operand may be a variable, number, boolean, string, expression, object, or combination of any other.
One of the most basic assignment operators is equal = , which is used to directly assign a value.
Assignment Operators List
In the following table if variable a is not defined then assume it to be 10.
The assignment operator = is the simplest value assigning operator which assigns a given value to a variable.
The assignment operators support chaining, which means you can assign a single value in multiple variables in a single line.
Addition assignment operator
The addition assignment operator += is used to add the value of the right operand to the value of the left operand and assigns the result to the left operand.
On the basis of the data type of variable, the addition assignment operator may add or concatenate the variables.
Subtraction assignment operator
The subtraction assignment operator -= subtracts the value of the right operand from the value of the left operand and assigns the result to the left operand.
If the value can not be subtracted then it results in a NaN .
Multiplication assignment operator
The multiplication assignment operator *= assigns the result to the left operand after multiplying values of the left and right operand.
Division assignment operator
The division assignment operator /= divides the value of the left operand by the value of the right operand and assigns the result to the left operand.
Remainder assignment operator
The remainder assignment operator %= assigns the remainder to the left operand after dividing the value of the left operand by the value of the right operand.
Exponentiation assignment operator
The exponential assignment operator **= assigns the result of exponentiation to the left operand after exponentiating the value of the left operand by the value of the right operand.
Left shift assignment
The left shift assignment operator <<= assigns the result of the left shift to the left operand after shifting the value of the left operand by the value of the right operand.
Right shift assignment
The right shift assignment operator >>= assigns the result of the right shift to the left operand after shifting the value of the left operand by the value of the right operand.
Unsigned right shift assignment
The unsigned right shift assignment operator >>>= assigns the result of the unsigned right shift to the left operand after shifting the value of the left operand by the value of the right operand.
Bitwise AND assignment
The bitwise AND assignment operator &= assigns the result of bitwise AND to the left operand after ANDing the value of the left operand by the value of the right operand.
Bitwise OR assignment
The bitwise OR assignment operator |= assigns the result of bitwise OR to the left operand after ORing the value of left operand by the value of the right operand.
Bitwise XOR assignment
The bitwise XOR assignment operator ^= assigns the result of bitwise XOR to the left operand after XORing the value of the left operand by the value of the right operand.
Logical AND assignment
The logical AND assignment operator &&= assigns value to left operand only when it is truthy .
Note : A truthy value is a value that is considered true when encountered in a boolean context.
Logical OR assignment
The logical OR assignment operator ||= assigns value to left operand only when it is falsy .
Note : A falsy value is a value that is considered false when encountered in a boolean context.
Logical nullish assignment
The logical nullish assignment operator ??= assigns value to left operand only when it is nullish ( null or undefined ).
Level Up Coding
The three new logical operators: nullish, AND, and OR are now available
Want to write less code?
There’s the QQ equals (logical nullish assignment), the And And Equals (logical AND assignment), and the Or Or Equals (logical OR assignment), each offering a better way to update and assign values using shorthand convenience operators.
I think these new operators are extremely useful because they allow for a handy way to change assignments only when certain logical conditions are met.
We don’t get unwanted side effects, just simple coalescing of values into variables with quick, concise operations.
Let’s look at the three new operators.
Logical nullish assignment (??=)
By writing this statement:
The equivalent logic translates into something like this:
So if x is nullish, this operator will update the value, but if x is NOT nullish, it will leave the existing value intact.
Logical AND assignment (&&=)
This one works just like how you’d use the Logical AND where the right side of the && doesn't get evaluated unless the expression on the left side is truthy.
So if x is truthy, this operator will update the value, but if x is falsy, it will leave the existing value intact.
Logical OR assignment (||=)
Finally, we have the logical or assignment . The logical OR assignment only assigns if the left-hand variable is falsy — again, anything that equals false , 0 , "" , null , undefined , and NaN and a few more values.
Written by Cameron Manavian
Father, Husband, Engineer, CTO, 15+ yrs of software engineering — cameronmanavian.com
More from Cameron Manavian and Level Up Coding
How to Debug a 502 on Kubernetes
Here is a thorough method to check the readiness of your application in order to determine the cause of your 502 problem.
AutoGPT is Taking Over the Internet: Here Are the Incredible Use Cases That Will Blow Your Mind
From acting as an intern to automating your work on discord..
Liu Zuo Lin
20 Python Concepts I Wish I Knew Way Earlier
# stuff i wish i learnt earlier as a beginner.
The Power of Kubernetes Cron Jobs
When i first got into web development over 15 years ago, one of the earliest ways i automated was by using cron jobs., recommended from medium.
Why I Keep Failing Candidates During Google Interviews…
They don’t meet the bar..
You’re Using ChatGPT Wrong! Here’s How to Be Ahead of 99% of ChatGPT Users
Master chatgpt by learning prompt engineering..
Stories to Help You Grow as a Software Developer
What is ChatGPT?
Stories to Help You Grow as a Designer
System Design Interview Basics: Difference Between API Gateway and Load Balancer
Often, we come across software architectural components that are part of every system design and feel as though we don’t have much….
How to Become a Good Backend Engineer (Fundamentals)
I have been a backend engineer for over 18 years and i witnessed technologies come and go but one thing always remain constant; the first….
Don’t Just LeetCode; Follow the Coding Patterns Instead
What if you don’t like to practice 100s of coding questions before the interview.
Anthony D. Mays
How to Practice LeetCode Problems (The Right Way)
Tl;dr: you’re doing it wrong. use “the six steps” any time you practice leetcode questions, preferably with another person. keep an….
Text to speech
The Logical OR assignment operator is used between two values. If the first value is false, the second value is assigned. Logical OR Assignment Example. let x =
An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal ( = )
The assignment (=) operator is used to assign a value to a variable. The assignment operation evaluates to the assigned value.
The simple assignment operator is used to assign a value to a variable. The assignment operation evaluates the assigned value. Chaining the
Use the assignment operator ( = ) to assign a value to a variable. Chain the assignment operators if you want to assign a single value to multiple variables.
Assignment operators are used to assign values to variables. For example, const x = 5;. Here, the = operator is used to assign value
The assignment operators support chaining, which
FREE Courses - https://automationstepbystep.com/Assignment Operators= Assign += Add and assign-= Sub and assign*= Multiply and assign/=