- Skip to main content
- Skip to search
- Skip to select language
- Get MDN Plus
- English (US)

SyntaxError: invalid assignment left-hand side
The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single = sign was used instead of == or === .
SyntaxError or ReferenceError , depending on the syntax.
What went wrong?
There was an unexpected assignment somewhere. This might be due to a mismatch of an assignment operator and an equality operator , for example. While a single = sign assigns a value to a variable, the == or === operators compare a value.
Typical invalid assignments
In the if statement, you want to use an equality operator ( === ), and for the string concatenation, the plus ( + ) operator is needed.
Assignments producing ReferenceErrors
Invalid assignments don't always produce syntax errors. Sometimes the syntax is almost correct, but at runtime, the left hand side expression evaluates to a value instead of a reference , so the assignment is still invalid. Such errors occur later in execution, when the line is actually executed.
Function calls, new calls, super() , and this are all values instead of references. If you want to use them on the left hand side, the assignment target needs to be a property of their produced values instead.
Note: In Firefox and Safari, the first example produces a ReferenceError in non-strict mode, and a SyntaxError in strict mode . Chrome throws a runtime ReferenceError for both strict and non-strict modes.
Using optional chaining as assignment target
Optional chaining is not a valid target of assignment.
Instead, you have to first guard the nullish case.
- Assignment operators
- Equality operators
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Why I get "Invalid left-hand side in assignment"?
There is code:
I get this error:
Why "&&" is wrong?
- ecmascript-6

- are you missing if before the first set of parentheses? – Dan O Dec 1, 2017 at 3:32
- 1 result[id] = list[id] should be result[id] === list[id] as it is a condition – Aravind Dec 1, 2017 at 3:33
- @Aravind that is not correct. – Pointy Dec 1, 2017 at 3:38
- @DanO "if" must not be important, because all logical operator in ( ), not { } – Turar Abu Dec 1, 2017 at 3:43
- @TurarAbu see my answer: the problem is that your assignment expression at the end of the && list is not in parentheses. – Pointy Dec 1, 2017 at 3:43
2 Answers 2
The problem is that the assignment operator, = , is a low-precedence operator, so it's being interpreted in a way you don't expect. If you put that last expression in parentheses, it works:
- The real problem is using logical operators for control flow. – user8897421 Dec 1, 2017 at 3:50
- 1 @rockstar well sure :) But it's not erroneous and lots of hard-core library code does stuff like that, so people will see it in "respectable" places. – Pointy Dec 1, 2017 at 3:55
There seems to be a typo in your code:
result[id] = list[id] should be result[id] == list[id] or result[id] === list[id] (if you're doing a strict comparison)
- No. The code posted is using JavaScript logical short-circuiting operators to conditionally perform an operation. The change you suggest would make the code do nothing at all. – Pointy Dec 1, 2017 at 3:37
- The trouble at 4'th line. – Turar Abu Dec 1, 2017 at 3:40
- There's no way = is a short hand for == or === . They have different meanings altogether. I checked in my console and it worked fine when I changed it to result[id] == list[id] – m-ketan Dec 1, 2017 at 3:41
- @m-ketan he wants to use the assignment operator ( = ). If the statement does not perform an assignment, the code is useless. – Pointy Dec 1, 2017 at 3:42
- @Pointy Oh I see it now. – m-ketan Dec 1, 2017 at 3:44
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged javascript angularjs ecmascript-6 or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
Hot Network Questions
- Any idea what set any of these are from? mostly minifigs and decorated bricks
- What video game is Charlie playing in Poker Face S01E07?
- Calculating probabilities from d6 dice pool (Degenesis rules for botches and triggers)
- How do you get out of a corner when plotting yourself into a corner
- Stored Procedure Tuning Help
- How to calculate lattice parameter?
- Is it possible to create a concave light?
- Topological invariance of rational Pontrjagin classes for non-compact spaces
- Theoretically Correct vs Practical Notation
- How can I explain to my manager that a project he wishes to undertake cannot be performed by the team?
- What is pictured in this SHERLOC camera?
- If a law is new but its interpretation is vague, can the courts directly ask the drafters the intent and official interpretation of their law?
- QGIS - Countif function
- Minimising the environmental effects of my dyson brain
- Simple template engine for bash, that can use csv data?
- Knocking Out Zombies
- Does Counterspell prevent from any further spells being cast on a given turn?
- What is a word for the arcane equivalent of a monastery? A place where magic is studied and practiced?
- "We, who've been connected by blood to Prussia's throne and people since Düppel"
- Is it possible to develop the Ubuntu kernel on the same computer that one works on?
- Biodiversity through radiation
- Can I tell police to wait and call a lawyer when served with a search warrant?
- Can airtags be tracked from an iMac desktop, with no iPhone?
- Finite abelian groups with fewer automorphisms than a subgroup
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

How to solve “Invalid left-hand side in assignment” in JavaScript

The “Invalid left-hand side in assignment” in JavaScript is a syntax error that often occurs in comparing values, such as using the “=” sign to compare. This article will give examples of everyday situations and how to fix them.
Table of Contents
What causes the “Invalid left-hand side in assignment” in JavaScript?
This is a very common syntax error. There are many causes of errors, such as wrong comparison signs, using “=” to compare two values, and not creating a variable to receive a value from the function. Here are examples of some errors.
Using the wrong comparison sign
“Invalid left-hand side in assignment” is an error caused by misspelled operator when comparing two values.
Using “=” to compare two values
This error also happens because instead of using “===”, you use “=” to compare.
Not creating a variable to receive a value from the function
This case leaves the wrong position of the variable.
Do not use square brackets when accessing object properties
For properties like this, we need to use square brackets.
Solution for the error “Invalid left-hand side in assignment” in JavaScript
Use the correct operator.
We need to pay attention to the comparison signs in expressions.
Pay attention to the position on either side of the “=”
To get the value of a function, we need to create a variable to the left of the “=” sign.

Use square brackets when accessing properties
For properties of objects with two or more words, we use square brackets.
The article has given some examples that lead to the error “Invalid left-hand side in assignment” in JavaScript. These are just syntax errors , pay attention to the process of writing code, and we will avoid such errors. We hope you can fix it quickly through this article. Good luck to you!
Maybe you are interested :
- TypeError: Assignment to Constant Variable in JavaScript
- Element type is invalid, expected a string (for built in components) or a class/function but got – How to solve?
- RangeError: Invalid time value in JavaScript

Carolyn Hise has three years of software development expertise. Strong familiarity with the following languages is required: Python, Typescript/Nodejs, .Net, Java, C++, and a strong foundation in Object-oriented programming (OOP).
Related Posts

Check If An Element Contains Specific Text Using JavaScript
- Bruce Warren
- January 18, 2023
You can use the String.includes() method and the textContent property to check if an element […]
How To Solve The Error: “ModuleNotFoundError: No module named ‘google.protobuf'” in Python
- Thomas Valen
The Error: “ModuleNotFoundError: No module named ‘google.protobuf’” in Python occurs because you have not installed […]
How To Solve The Error: “ModuleNotFoundError: No module named ‘crispy_forms'” in Python
The Error: “ModuleNotFoundError: No module named ‘crispy_forms’” in Python happens because you have not installed […]
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Save my name, email, and website in this browser for the next time I comment.
Invalid left-hand side in assignment in JavaScript [Solved]

Borislav Hadzhiev
Reading time · 2 min

Photo from Unsplash
Invalid left-hand side in assignment in JavaScript [Solved] #
The "Invalid left-hand side in assignment" error occurs when we have a syntax error in our JavaScript code.
The most common cause is using a single equal sign instead of double or triple equals in a conditional statement.
To resolve the issue, make sure to correct any syntax errors in your code.

Here are some examples of how the error occurs.
Use double or triple equals when comparing values #
The most common cause of the error is using a single equal sign = instead of double or triple equals when comparing values.
The engine interprets the single equal sign as an assignment and not as a comparison operator.
We use a single equals sign when assigning a value to a variable.
However, we use double equals (==) or triple equals (===) when comparing values.
Use bracket notation for object properties that contain hyphens #
Another common cause of the error is trying to set an object property that contains a hyphen using dot notation.
You should use bracket [] notation instead, e.g. obj['key'] = 'value' .
Assigning the result of calling a function to a value #
The error also occurs when trying to assign the result of a function invocation to a value as shown in the last example.
If you aren't sure where to start debugging, open the console in your browser or the terminal in your Node.js application and look at which line the error occurred.
The screenshot above shows that the error occurred in the index.js file on line 25 .
You can hover over the squiggly red line to get additional information on why the error was thrown.

Web Developer

Copyright © 2023 Borislav Hadzhiev
- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- DevOps(Live)
- Explore More Live Courses
- Interview Preparation Course
- Data Science (Live)
- 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
- Android App Development with Kotlin(Live)
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- React JS (Basic to Advanced)
- JavaScript Foundation
- Complete Data Science Program(Live)
- Mastering Data Analytics
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Binary Tree
- Binary Search Tree
- Advanced Data Structure
- All Data Structures
- 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
- Searching Algorithms
- Sorting Algorithms
- Graph Algorithms
- Pattern Searching
- Geometric Algorithms
- Mathematical
- Bitwise Algorithms
- Randomized Algorithms
- Greedy Algorithms
- Dynamic Programming
- Divide and Conquer
- Backtracking
- Branch and Bound
- All Algorithms
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Design Patterns
- System Design Tutorial
- Multiple Choice Quizzes
- 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
- BlueprintJS
- TensorFlow.js
- English Grammar
- School Programming
- Number System
- Trigonometry
- Probability
- Mensuration
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- 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)
- Machine Learning
- Data Science
- Mathematics
- 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
- Software Design Patterns
- 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
- 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
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Testimonials
- Student Chapter
- Geek on the Top
- Geography Notes
- History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- UPSC Previous Year Papers
- 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
- Apply for a Job
- Apply through Jobathon
- Hire through Jobathon
- 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
- Solving For India-Hackthon
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- JS-Function
- JS-Generator
- JS-Expressions
- JS-ArrayBuffer
- JS-Tutorial
- Web Development
- Web-Technology
Related Articles
- Write Articles
- Pick Topics to write
- Guidelines to Write
- Get Technical Writing Internship
- Write an Interview Experience
JavaScript ReferenceError – Invalid assignment left-hand side
- How to copy the content of a div into another div using jQuery ?
- jQuery append() Method
- jQuery appendTo() Method
- jQuery clone() Method
- How to get the entire HTML document as a string in JavaScript ?
- Node.js fs.readdir() Method
- Node.js fs.readdirSync() Method
- Node.js fs.readFileSync() Method
- Node.js | fs.writeFileSync() Method
- Node.js fs.writeFile() Method
- Node.js fs.readFile() Method
- How to read a local text file using JavaScript?
- Javascript | Program to read text File
- JavaScript Program to write data in a text File
- Understanding basic JavaScript code
- JavaScript if-else
- Switch Case in JavaScript
- Loops in JavaScript
- Functions in JavaScript
- JavaScript Modules
- JavaScript Importing and Exporting Modules
- JavaScript Hoisting
- JavaScript | Callbacks
- JavaScript Type Conversion
- How to calculate the number of days between two dates in JavaScript ?
- File uploading in React.js
- Hide elements in HTML using display property
- How to append HTML code to a div using JavaScript ?
- Difference between var and let in JavaScript
- Last Updated : 05 Jan, 2023
This JavaScript exception invalid assignment left-hand side occurs if there is a wrong assignment somewhere in code. A single “=” sign instead of “==” or “===” is an Invalid assignment.
Error Type:
Cause of the error: There may be a misunderstanding between the assignment operator and a comparison operator.
Basic Example of ReferenceError – Invalid assignment left-hand side, run the code and check the console
Example 1: In this example, “=” operator is misused as “==”, So the error occurred.
Example 2: In this example, the + operator is used with the declaration, So the error has not occurred.
Output:
Please Login to comment...
- shobhit_sharma
- JavaScript-Errors
- Web Technologies
Improve your Coding Skills with Practice
Start your coding journey now.

IMAGES
VIDEO
COMMENTS
Invalid assignments don't always produce syntax errors. Sometimes the syntax is almost correct, but at runtime, the left hand side expression evaluates to a value instead of a reference, so the assignment is still invalid. Such errors occur later in execution, when the line is actually executed.
The problem is that the assignment operator, =, is a low-precedence operator, so it's being interpreted in a way you don't expect. If you put that last expression in parentheses, it works: for (let id in list) ( (!q.id || (id == q.id)) && (!q.name || (list [id].name.search (q.name) > -1)) && (result [id] = list [id]) ); Share
Uncaught SyntaxError: Invalid left-hand side in assignment Using “=” to compare two values This error also happens because instead of using “===”, you use “=” to compare. Example: 4 1 2 if (10 = 10) { 3 console.log("test"); 4 } Output: Uncaught SyntaxError: Invalid left-hand side in assignment
The "Invalid left-hand side in assignment" error occurs when we have a syntax error in our JavaScript code. The most common cause is using a single equal sign instead of double or triple equals in a conditional statement. To resolve the issue, make sure to correct any syntax errors in your code.
ReferenceError: invalid assignment left-hand side Error Type: ReferenceError Cause of the error: There may be a misunderstanding between the assignment operator and a comparison operator. Basic Example of ReferenceError – Invalid assignment left-hand side, run the code and check the console Example 1: Javascript if (Math.PI = 10 || Math.PI = 5) {