- 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
Hot Network Questions
- Is it suspicious or odd to stand by the gate of a GA airport watching the planes?
- Partner is not responding when their writing is needed in European project application
- The region and polygon don't match. Is it a bug?
- Is a PhD visitor considered as a visiting scholar?
- Is there a solutiuon to add special characters from software and how to do it
- What sort of strategies would a medieval military use against a fantasy giant?
- Redoing the align environment with a specific formatting
- Does a barbarian benefit from the fast movement ability while wearing medium armor?
- What is a word for the arcane equivalent of a monastery? A place where magic is studied and practiced?
- Who owns code in a GitHub organization?
- About an argument in Famine, Affluence and Morality
- My code is GPL licensed, can I issue a license to have my code be distributed in a specific MIT licensed project?
- How to handle a hobby that makes income in US
- Short story taking place on a toroidal planet or moon involving flying
- Recovering from a blunder I made while emailing a professor
- Does a summoned creature play immediately after being summoned by a ready action?
- Does Counterspell prevent from any further spells being cast on a given turn?
- Time arrow with "current position" evolving with overlay number
- How do I align things in the following tabular environment?
- Why do small African island nations perform better than African continental nations, considering democracy and human development?
- Is it plausible for constructed languages to be used to affect thought and control or mold people towards desired outcomes?
- Checking system vs. SEPA and the like
- ERROR: CREATE MATERIALIZED VIEW ... WITH DATA cannot be executed from a function
- The difference between the phonemes /p/ and /b/ in Japanese
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 .

- Get Started
Jan 26, 2017 6:00:03 AM | JavaScript - ReferenceError: invalid assignment left-hand side
Today we examine the invalid assignment error, which is thrown, as the name implies, when code attempts to perform an invalid assignment somewhere.
Next on the list in our extensive JavaScript Error Handling series we're going to examine the Invalid Left-Hand Assignment error in greater detail. The Invalid Left-Hand Assignment error is a sub-object of ReferenceError and is thrown, as the name implies, when code attempts to perform an invalid assignment somewhere.
In this post we'll look at a few code examples to illustrate some common methods of producing an Invalid Left-Hand Assignment error, as well as examine how to handle this error when it rears its ugly head. Let the party begin!
The Technical Rundown
- All JavaScript error objects are descendants of the Error object, or an inherited object therein.
- The ReferenceError object is inherited from the Error object.
- The Invalid Left-Hand Assignment error is a specific type of ReferenceError object.
When Should You Use It?
As one of the simplest JavaScript errors to understand, the Invalid Left-Hand Assignment error appears in only a handful of situations in which code is attempting to pass an assignment incorrectly. While this is generally thought of as a syntactic issue, JavaScript defines this particular assignment error as a ReferenceError, since the engine effectively assumes an assignment to a non-referenced variable is being attempted.
The most common example of an Invalid Left-Hand Assignment error is when attempting to compare a value using a assignment operator (=), rather than using a proper comparison operator (== or ===). For example, here we're attempting to perform a basic comparison of the variable name with the values John or Fred. Unfortunately, we've made the mistake of using the assignment operator =, instead of a comparison operator such as == or ===:
try { var name = 'Bob'; if (name = 'John' || name = 'Fred') { console.log(`${name} returns!`) } else { console.log(`Just ${name} this time.`) } } catch (e) { if (e instanceof ReferenceError) { printError(e, true); } else { printError(e, false); } }
Sure enough, rather than giving us an output, the JavaScript engine produces the expected Invalid Left-Hand Assignment error:
It's worth noting that catching an Invalid Left-Hand Assignment error with a typical try-catch block is particular difficult, because the engine parses the code from inside out, meaning inner code blocks are parsed and executed before outer blocks. Since the issue of using a = assignment operator instead of a == comparison operator means the actual structure of the code is changed from the expected, the outer try-catch fails to be parsed and properly executed. In short, this means Invalid Left-Hand Assignment errors are always "raw", without any simple means of catching them.
Another common method for producing an Invalid Left-Hand Assignment error is when attempting to concatenate a string value onto a variable using the addition assignment += operator, instead of the concatenation operator +. For example, below we're attempting to perform concatenation on the name variable on multiple lines, but we've accidentally used the += operator:
try { var name = 'Bob' += ' Smith';
console.log(`Name is ${name}.`); } catch (e) { if (e instanceof ReferenceError) { printError(e, true); } else { printError(e, false); } }
This isn't the syntax JavaScript expects when concatenating multiple values onto a string, so an Invalid Left-Hand Assignment error is thrown:
To resolve this, we simply need to replace += with the concatenation operator +:
try { var name = 'Bob' + ' Smith';
Now we skip the Invalid Left-Hand Assignment error entirely and get our expected output indicating the full name stored in the name variable:
To dive even deeper into understanding how your applications deal with JavaScript Errors, check out the revolutionary Airbrake JavaScript error tracking tool for real-time alerts and instantaneous insight into what went wrong with your JavaScript code.
Written By: Frances Banks
You may also like.
Dec 28, 2016 8:00:56 AM | JavaScript Error Handling - ReferenceError: assignment to undeclared variable “x”
Feb 15, 2017 7:41:35 am | javascript error handling: syntaxerror: "use strict" not allowed in function with non-simple parameters, may 21, 2017 9:00:51 am | javascript errors - syntaxerror: test for equality mistyped as assignment.
© Airbrake. All rights reserved. Terms of Service | Privacy Policy | DPA
[Solved]-Syntax Error: Invalid left-hand side in assignment expression-React Native
Optional chaining should be used when reading the value, not when assigning it. You can update the piece of code to this:
Edit: Mistake pointed out by Felix King
Related Query
- Syntax Error: Invalid left-hand side in assignment expression
- I am getting Invalid regular expression error while running npm start
- Invalid Regular Expression error after running expo start command
- React element type is invalid - ES6 destructuring syntax error when passing props
- Error while running ESLint: Invalid regular expression flags
- React native - Invalid regular expression error
- The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage
- getting syntax error while putting ternary expression inside a string interpolation
- Getting the error that Expected an assignment or function call and instead saw an expression no-unused-expressions?
- error jest: Warning: React.createElement: type is invalid
- Amazon Rekogntion Image: error InvalidImageFormatException: Request has invalid image format
- CocoaPods error while doing "pod install": [!] Invalid `Podfile` file: uninitialized constant Pod::Podfile::Flurry.
- Why am I getting an error that says Property assignment expected when I'm not even using TypeScript?
- How to add icon left side in InputText in React Native
- How to fix "Support for the experimental syntax 'classProperties' isn't currently enabled" error if it has been already enabled?
- Error when setting up Tab Navigator - ' Got an invalid Value for 'component' prop for screen 'Home'
- I am trying to export this JSON data for importing in the project however it shows unexpected syntax error
- Getting syntax error for create a new project using create-react-native-app
- error Can't add "react-navigation": invalid package version undefined when run yarn
- Error Invalid regular expression: Metro Bundler process exited with code 1
- React Native Pod Error - [!] Invalid `Podfile` file: 767: unexpected token at ''. | Related Issue #448
- React Native, passing locale parameter from i18next to Axios config file gives Invalid hook call error
- Getting an error in Reactjs. It says Unhandled Rejection (TypeError). But I already told it what to do if user types invalid name in input
- Syntax Error Unexpected Token, React Native
- Super expression error must either be null or a function
- How to access Enum in typescript ? giving error "Element implicitly has an any type because index expression is not of type number"
- Messages displayed on one side only (left hand side of the screen) - react-native-gifted-chat
- Super Expression Error in React Native Project
- Invalid hook call. Hooks can only be called inside of the body of a function component, Error only occurs in browser not on mobile
- getting error Invalid hook call when I call one component in class component
More Query from same tag
- React Native, How to convert nested if else into switch statement?
- Possible unhandled promise rejection on hardware back press
- How can I speed up my array search function?
- React Native BackgroundTimer API Fetch respons more than once
- Useragent not working in react-native-webview
- Set Background to an Image for Save to gallery
- React Native Firebase updating to 5.0.0 ios errors
- How to use an icon instead of the original back button in React Navigation?
- How update ListView?
- Argument of type '{ [x: string]: any; }' is not assignable to parameter of type 'Contact'
- How Can Bind the Dragged view inside ScrollView item?
- react-native-google-places-autocomplete not working on React native 0.61
- ReactWebViewManager error after upgrading to 0.60.5
- How to get list with of property from array of objects unless it contains another item with certain value?
- Way to handle refresh token
- There is a way to make less request in firebase?
- React Native Task :react-native-maps:compileDebugJavaWithJavac FAILED
- Cannot update during render, on Image onError function
- Check if all Input component fields are filled, then enable submit button
- unexpected token ':'.parse - React native Android
- How to detect where an alert dialog is created in React Native android
- How to modify data structure fetched from elasticsearch to render item in a react native flatlist?
- Updating value inside nested object of object in React Native
- JS function not getting called inside string html in react
- ReactNative - Warning: Cannot update a component from inside the function body of a different component
- How to call functions from another js file in app.js
- React Router and passing props
- Undefined values when using map array in Javascript
- Custom button Component in React Native is not accepting props
- Cant Access State from a function

Copyright 2023 www.appsloveworld.com . All rights reserved.
- 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.
- No suggested jump to results
- Notifications
"Uncaught ReferenceError: Invalid left-hand side in assignment" when building with certain dependencies #45
gnestor commented Nov 30, 2016
- 👍 1 reaction
blink1073 commented Nov 30, 2016
Sorry, something went wrong.
blink1073 commented Dec 1, 2016
gnestor commented Dec 1, 2016 • edited
Gnestor commented dec 5, 2016.
No branches or pull requests
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

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 ReferenceError: Invalid left-hand side in assignment To resolve this, we simply need to replace += with the concatenation operator +:
Coding example for the question Syntax Error: Invalid left-hand side in assignment expression-React Native
i got this error when i try to import this package Invalid left-hand side in assignment !(function webpackMissingModule() { var e = new Error("Cannot find module ...
In assignment patterns, the pattern does not start with a keyword. Each destructured property is assigned to a target of assignment — which may either be declared beforehand with var or let, or is a property of another object — in general, anything that can appear on the left-hand side of an assignment expression.
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. Message: ReferenceError: invalid assignment left-hand side Error Type: ReferenceError
I'm working on a mimerender extension that depends on react-data-grid. When building the extension for notebook, everything works as expected. However, when building for lab, the webpack builds successfully, but when I load it fails with: Uncaught ReferenceError: Invalid left-hand side in assignment. It points to this line:
Uncaught ReferenceError: Invalid left-hand side in an assignment at index.js:25 SyntaxError: Invalid left-hand side in assignment at ESMLoader.moduleStrategy ...