• Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free
  • Português (do Brasil)

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 statement 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

Invalid left-hand side in assignment in JavaScript [Solved]

avatar

Last updated: Mar 2, 2024 Reading time · 2 min

banner

# 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.

invalid left hand side in assignment error

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.

use 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.

assignment vs equality

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.

use bracket notation for object properties containing hyphens

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.

book cover

Borislav Hadzhiev

Web Developer

buy me a coffee

Copyright © 2024 Borislav Hadzhiev

How to fix SyntaxError: invalid assignment left-hand side

by Nathan Sebhastian

Posted on Jul 10, 2023

Reading time: 3 minutes

olplayer error loading invalid left hand side in assignment

When running JavaScript code, you might encounter an error that says:

Both errors are the same, and they occured when you use the single equal = sign instead of double == or triple === equals when writing a conditional statement with multiple conditions.

Let me show you an example that causes this error and how I fix it.

How to reproduce this error

Suppose you have an if statement with two conditions that use the logical OR || operator.

You proceed to write the statement as follows:

When you run the code above, you’ll get the error:

This error occurs because you used the assignment operator with the logical OR operator.

An assignment operator doesn’t return anything ( undefined ), so using it in a logical expression is a wrong syntax.

How to fix this error

To fix this error, you need to replace the single equal = operator with the double == or triple === equals.

Here’s an example:

By replacing the assignment operator with the comparison operator, the code now runs without any error.

The double equal is used to perform loose comparison, while the triple equal performs a strict comparison. You should always use the strict comparison operator to avoid bugs in your code.

Other causes for this error

There are other kinds of code that causes this error, but the root cause is always the same: you used a single equal = when you should be using a double or triple equals.

For example, you might use the addition assignment += operator when concatenating a string:

The code above is wrong. You should use the + operator without the = operator:

Another common cause is that you assign a value to another value:

This is wrong because you can’t assign a value to another value.

You need to declare a variable using either let or const keyword, and you don’t need to wrap the variable name in quotations:

You can also see this error when you use optional chaining as the assignment target.

For example, suppose you want to add a property to an object only when the object is defined:

Here, we want to assign the age property to the person object only when the person object is defined.

But this will cause the invalid assignment left-hand side error. You need to use the old if statement to fix this:

Now the error is resolved.

The JavaScript error SyntaxError: invalid assignment left-hand side occurs when you have an invalid syntax on the left-hand side of the assignment operator.

This error usually occurs because you used the assignment operator = when you should be using comparison operators == or === .

Once you changed the operator, the error would be fixed.

I hope this tutorial helps. Happy coding!

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

Hello! This website is dedicated to help you learn tech and data science skills with its step-by-step, beginner-friendly tutorials. Learn statistics, JavaScript and other programming languages using clear examples written for people.

Learn more about this website

Connect with me on Twitter

Or LinkedIn

Type the keyword below and hit enter

Click to see all tutorials tagged with:

ReferenceError: invalid assignment left-hand side

The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. For example, a single " = " sign was used instead of " == " or " === ".

ReferenceError .

What went wrong?

There was an unexpected assignment somewhere. This might be due to a mismatch of a 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.

  • Assignment operators
  • Equality operators

© 2005–2021 MDN contributors. Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side

The Linux Code

Demystifying JavaScript‘s "Invalid Assignment Left-Hand Side" Error

Assignment operations are fundamental in JavaScript – we use them all the time to assign values to variables. However, occasionally you may come across a confusing error:

This "Invalid Assignment Left-Hand Side" error occurs when you try to assign a value to something that JavaScript will not allow. At first glance, this doesn‘t seem to make sense – isn‘t assignment valid in JS?

In this comprehensive guide, we‘ll demystify exactly when and why this error occurs and equip you with the knowledge to resolve it.

Assignment and Equality Operators in JavaScript

To understand this error, we first need to understand the role of assignment and equality operators in JavaScript.

The Assignment Operator

The assignment operator in JS is the single equals sign = . It is used to assign a value to a variable, like so:

This stores the value 10 in the variable x . Simple enough!

The Equality Operator

The equality operator == checks if two values are equal to each other. For example:

The equality operator == is different from the assignment operator = – it compares values rather than assigning them.

Mixing up assignment and equality is a common source of bugs in JS programs.

Immutable vs Mutable Values in JavaScript

In JavaScript, some values are immutable – they cannot be changed or reassigned. The most common immutable values are:

  • Constants like Math.PI
  • Primitive values like undefined or null

Trying to reassign an immutable value will lead to our error.

On the other hand, mutable values like variables can be reassigned:

Keeping mutable vs immutable values in mind is key to avoiding "Invalid Assignment" errors.

When and Why This Error Occurs

There are two main situations that cause an "Invalid Assignment Left-Hand Side" error:

1. Attempting to Mutate an Immutable Constant

Immutable constants in JavaScript cannot be reassigned. For example:

Core language constants like Math.PI are immutable. Trying to alter them with the assignment operator = will throw an error.

You‘ll also get an error trying to reassign a declared const variable:

2. Accidentally Using Assignment = Instead of Equality ==

Another common source of this error is accidentally using the single = assignment operator when you meant to use the == equality operator:

This can lead to logical errors, as you are assigning 10 to x rather than checking if x equals 10 .

According to a 2020 survey, over 40% of JavaScript developers have made this mistake that led to bugs in their code.

Example Error Message

When an invalid assignment occurs, you‘ll see an error like:

This tells us there is an invalid assignment on line 2 of myScript.js . The full error message gives us an important clue that an assignment operation is causing the issue.

Let‘s look at a full code example:

Running this would result in our error:

Now that we‘ve seen the error, let‘s walk through debugging techniques.

Debugging an Invalid Assignment

When the "Invalid Assignment Left-Hand Side" error appears, follow these steps:

  • Identify the exact line causing the issue from the error stack trace
  • Check if the line is trying to reassign a constant value
  • If so, use a variable instead of a constant
  • Otherwise, verify = is intended and not == for equality

Let‘s demonstrate with our code example:

The error said line 2 was invalid, so we examine it:

Aha! We‘re trying to assign to the constant PI . Since constants are immutable, this causes an error.

To fix, we need to use a mutable variable instead:

That‘s all there is to debugging simple cases like this. Now let‘s look at some tips to avoid the problem altogether.

Avoiding the "Invalid Assignment" Error

With knowledge of assignments and equality in JavaScript, you can avoid these errors with:

  • Using const for true constants – Avoid reassignment by default
  • Declaring variables rather than trying to mutate language builtins
  • Take care with = vs == – Understand what each one does
  • Use a linter – Catches many invalid assignments before runtime
  • Improve testing – Catch assumption errors around assignments early
  • Refactor code – Make invalid assignments impossible through design

Avoiding mutations and validating equality logic will steer you clear of this problem.

Why This Error Matters

At first glance, the "Invalid Assignment Left-Hand Side" error may seem minor. However, it points to flawed assumptions around assignments and equality in JavaScript that can cause major issues down the line.

That‘s why understanding this error is about more than just fixing that one line of code. It represents a milestone in solidifying your mental models around immutable values, variables, assignment and equality in JavaScript.

Making assignments consciously and validating them through linting and testing will level up your code quality and make you a more proficient JS developer.

Key Takeaways

To recap, the core takeaways around the "Invalid Assignment Left-Hand Side" error are:

  • It occurs when trying to assign a value to a constant or immutable value
  • Accidentally using = instead of == for equality checks is another common cause
  • The error message directly states "invalid assignment" which provides a clue
  • Debug by checking for assignment to constants or verifying equality checks
  • Declare variables and use const properly to avoid reassignment errors
  • Differentiate between = assignment and == equality checks

Learning to debug and avoid this error will improve your fundamental JavaScript skills. With time, you‘ll handle invalid assignments with ease!

Dealing with "Invalid Assignment Left-Hand Side" errors may seem cryptic initially. But by leveraging the error message itself and understanding assignments in JavaScript, you can swiftly resolve them.

Immutable values and equality logic are at the heart of these errors. With care and awareness around assignments, you can sidestep these issues in your code going forward.

Debugging and resolving errors like this are an important part of the JavaScript learning journey. Each one makes you a little wiser! So don‘t get discouraged when you run into an "Invalid Assignment" error. Leverage the techniques in this guide to level up your skills.

You maybe like,

Related posts, "what‘s the fastest way to duplicate an array in javascript".

As a fellow JavaScript developer, you may have asked yourself this same question while building an application. Copying arrays often comes up when juggling data…

1 Method: Properly Include the jQuery Library

As a JavaScript expert and editor at thelinuxcode.com, I know first-hand how frustrating the "jQuery is not defined" error can be. This single error can…

A Beginner‘s Guide to Formatting Decimal Places in JavaScript

As a web developer, you‘ll frequently run into situations where you need to display nice, cleanly formatted numbers in your interfaces. Have you ever had…

A Complete Guide to Dynamic DOM Manipulation with JavaScript‘s appendChild()

As a Linux developer building modern web applications, being able to efficiently interact with the DOM (Document Object Model) using JavaScript is a crucial skill.…

A Complete Guide to Dynamically Adding Properties in JavaScript

As an experienced JavaScript developer, I often get asked about the different ways to add properties to objects in JavaScript. While this may seem like…

A Complete Guide to Dynamically Changing Image Sources with JavaScript

This comprehensive tutorial explains how to change image sources dynamically in JavaScript. We‘ll cover the ins and outs of swapping images on the fly using…

Airbrake logo144-1

  • 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.

 alt=

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

  • DSA with JS - Self Paced
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Operator
  • JS Projects
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
  • JavaScript Error Object Complete Reference

JS Range Error

  • JavaScript RangeError - Invalid date
  • JavaScript RangeError - Repeat count must be non-negative

JS Reference Error

  • JavaScript ReferenceError - Can't access lexical declaration`variable' before initialization
  • JavaScript ReferenceError - Invalid assignment left-hand side
  • JavaScript ReferenceError - Assignment to undeclared variable
  • JavaScript ReferenceError - Reference to undefined property "x"
  • JavaScript ReferenceError - variable is not defined
  • JavaScript ReferenceError Deprecated caller or arguments usage

JS Syntax Error

  • JavaScript SyntaxError - Illegal character
  • JavaScript SyntaxError - Identifier starts immediately after numeric literal
  • JavaScript SyntaxError - Function statement requires a name
  • JavaScript SyntaxError - Missing } after function body
  • JavaScript SyntaxError - Missing } after property list
  • JavaScript SyntaxError - Missing variable name
  • JavaScript SyntaxError - Missing ] after element list
  • JavaScript SyntaxError - Invalid regular expression flag "x"
  • JavaScript SyntaxError "variable" is a reserved identifier
  • JavaScript SyntaxError - Missing ':' after property id
  • JavaScript SyntaxError - Missing ) after condition
  • JavaScript SyntaxError - Missing formal parameter
  • JavaScript SyntaxError - Missing ; before statement
  • JavaScript SyntaxError - Missing = in const declaration
  • JavaScript SyntaxError - Missing name after . operator
  • JavaScript SyntaxError - Redeclaration of formal parameter "x"
  • JavaScript SyntaxError - Missing ) after argument list
  • JavaScript SyntaxError - Return not in function
  • JavaScript SyntaxError: Unterminated string literal
  • JavaScript SyntaxError - Applying the 'delete' operator to an unqualified name is deprecated
  • JavaScript SyntaxError - Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
  • JavaScript SyntaxError - Malformed formal parameter
  • JavaScript SyntaxError - "0"-prefixed octal literals and octal escape sequences are deprecated
  • JavaScript SyntaxError - Test for equality (==) mistyped as assignment (=)?
  • JavaScript SyntaxError - "x" is not a legal ECMA-262 octal constant

JS Type Error

  • JavaScript TypeError - "X" is not a non-null object
  • JavaScript TypeError - "X" is not a constructor
  • JavaScript TypeError - "X" has no properties
  • JavaScript TypeError - "X" is (not) "Y"
  • JavaScript TypeError - "X" is not a function
  • JavaScript TypeError - 'X' is not iterable
  • JavaScript TypeError - More arguments needed
  • JavaScript TypeError - "X" is read-only
  • JavaScript TypeError - Reduce of empty array with no initial value
  • JavaScript TypeError - Can't assign to property "X" on "Y": not an object
  • JavaScript TypeError - Can't access property "X" of "Y"
  • JavaScript TypeError - Can't define property "X": "Obj" is not extensible
  • JavaScript TypeError - X.prototype.y called on incompatible type
  • JavaScript TypeError - Invalid assignment to const "X"
  • JavaScript TypeError - Property "X" is non-configurable and can't be deleted
  • JavaScript TypeError - Can't redefine non-configurable property "x"
  • JavaScript TypeError - Variable "x" redeclares argument
  • JavaScript TypeError - Setting getter-only property "x"
  • JavaScript TypeError - Invalid 'instanceof' operand 'x'
  • JavaScript TypeError - Invalid Array.prototype.sort argument
  • JavaScript TypeError - Cyclic object value
  • JavaScript TypeError - Can't delete non-configurable array element

JS Other Errors

  • JavaScript URIError | Malformed URI Sequence
  • JavaScript Warning - Date.prototype.toLocaleFormat is deprecated
  • Logging Script Errors in JavaScript

JS Error Instance

  • JavaScript Error message Property
  • JavaScript Error name Property
  • JavaScript Error.prototype.toString() Method

JavaScript ReferenceError – Invalid assignment left-hand side

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...

Similar reads.

  • JavaScript-Errors
  • Web Technologies

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

RPG Maker Forums

  • Search forums
  • Game Development Engines
  • RPG Maker Javascript Plugins
  • Javascript/Plugin Support

Is this correct syntax for setting a value?

  • Thread starter Spindaboy
  • Start date Apr 5, 2016
  • Tags syntax

Spindaboy

  • Apr 5, 2016

What is wrong with this? I keep getting the error, "Invalid left-hand in assignment." I am trying to set variable 76 to the ID of the 1st actor in the party. $gameVariables.setValue(76) = $gameParty.actor(0).id  

mrcopra

gameVariables.setValue(76,gameParty.actor(0).id)  

It says gameVariables isn't defined.  

lol sorry my mistake i forgot $ $gameVariables.setValue(76,gameParty.actor(0).id)  

gameParty is not defined.  

$gameVariables.setValue(76,$gameParty.members()[0].actorId())  

Thanks :3  

Latest Threads

ZombieKidzRule

  • Started by ZombieKidzRule
  • Today at 7:31 PM
  • Started by Souliosis
  • Today at 7:22 PM

NalamiHUN

  • Started by NalamiHUN
  • Today at 6:14 PM

Indinera

  • Started by Indinera
  • Today at 5:44 PM

Latest Posts

Archeia

  • Latest: Archeia
  • 25 minutes ago

ATT_Turan

  • Latest: ATT_Turan
  • 27 minutes ago
  • 43 minutes ago

NamEtag

  • Latest: NamEtag
  • 48 minutes ago

Latest Profile Posts

Poryg

Newest members

ZumgoZoy

Forum statistics

  • This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register. By continuing to use this site, you are consenting to our use of cookies. Accept Learn more…
  • Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

  • Recent Discussions
  • 4.9K All Categories
  • 1.2K Help! with 1.x
  • 333 Workshop
  • 3K Help! with 2.0
  • 343 Chit-Chat

: bad expression: Invalid left-hand side in assignment

Dazakiwi38

[[Open door|Sorter1][$CurrentPos.LocEntry[3] = 5; $CurrentPos.LocWall[3] = 5; $Reset = true; $DoorOpened = true]]
Originally I did try that normal link code method and what i was trying to achieve wasn't working so i wrongly assumed that you couldn't have [] within the link|passage code because it uses them, i was assuming it wasn't passing the values.
// WRONG: The closing square bracket of the array touches the closing pair of the markup, making them ambiguous. [[Go where?|There][$list to ["A", "B"]]] // CORRECT: The closing square bracket of the array is separated from the closing pair of the markup by a space. [[Go where?|There][$list to ["A", "B"] ]]

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 statement 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

© 2005–2023 MDN contributors. Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side

MaplePrimes

Ask a Question

Create a post, question: error, invalid left hand side in assignment.

Tags are words are used to describe and categorize your content. Combine multiple words with dashes(-), and seperate tags with spaces.

olplayer error loading invalid left hand side in assignment

Here is my code

ma[1] := [-885.880598855072776, [bh = 0., g0h = 0., g1h = 0.825946224722250e-4]]

ma[2] := [-877.957885609114328, [bh = 347.116836805625, g0h = 0., g1h = 0.164861392564e-3]]

ma[3] := [-863.445203144006655, [bh = 0., g0h = 0., g1h = 0.787090377403668e-4]]

avb := 90.5276611129000; avg0 := 0; avg1 := 0.92225359e-4;

for j from 1 to 3 do

assign(ma[j][2]); A[j] := [(avb-bh)^2, (avg0-g0h)^2, (avg1-g1h)^2] 

Result is that

A[1] := [4763.19965962732, 0., 1.13103562500664*10^(-10)]

Error, invalid left hand side in assignment

 it only shows A[1], but no A[2] and A[3]

Please help!

2109 views More... Contact Author Subscribe Generate PDF Answer Reply Share Branch Create a new Post in reply Ask a related Question Flag

  • You must enter a body with at least 15 characters
  • That username is already taken by another member
  • User name doesn't fit requirements

olplayer error loading invalid left hand side in assignment

You must be logged into your Facebook account in order to share via Facebook.

Click the button below to share this on Google+. A new window will open.

You must be logged in to your Twitter account in order to share. Click the button below to login (a new window will open.)

Please log-in to your MaplePrimes account.

Wrong Email/Password. Please try again.

Generating PDF…

Error occurred during PDF generation. Please refresh the page and try again

Login to Your MaplePrimes Account

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid left-hand side in assignment #846

@pbassut

pbassut commented Dec 12, 2020 • edited

  • 👍 4 reactions

@raslasarslas

raslasarslas commented Apr 25, 2021

Sorry, something went wrong.

pbassut commented Apr 25, 2021

@erodrig

erodrig commented May 23, 2021

@dphang

dphang commented May 25, 2021

@randalpinto

javiermanzano commented Aug 24, 2022 • edited

No branches or pull requests

@javiermanzano

COMMENTS

  1. SyntaxError: invalid assignment left-hand side

    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 statement is actually executed. js. function foo() { return { a: 1 }; } foo ...

  2. Why I get "Invalid left-hand side in assignment"?

    7. 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]) ); The real problem is ...

  3. Invalid left-hand side in assignment in JavaScript [Solved]

    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.

  4. How to fix SyntaxError: invalid assignment left-hand side

    SyntaxError: invalid assignment left-hand side or SyntaxError: Invalid left-hand side in assignment Both errors are the same, and they occured when you use the single equal = sign instead of double == or triple === equals when writing a conditional statement with multiple conditions.

  5. ReferenceError: Invalid left-hand side in assignment

    Common reasons for the error: use of assignment ( =) instead of equality ( == / ===) assigning to result of function foo() = 42 instead of passing arguments ( foo(42)) simply missing member names (i.e. assuming some default selection) : getFoo() = 42 instead of getFoo().theAnswer = 42 or array indexing getArray() = 42 instead of getArray()[0 ...

  6. Errors: Invalid assignment left-hand side

    ReferenceError: invalid assignment left-hand side The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. For example, a single "=" sign was used instead of "==" or "===".

  7. Demystifying JavaScript's "Invalid Assignment Left-Hand Side" Error

    Assignment operations are fundamental in JavaScript - we use them all the time to assign values to variables. However, occasionally you may come across a confusing error:

  8. JavaScript

    Today we examine the invalid assignment error, which is thrown, as the name implies, when code attempts to perform an invalid assignment somewhere.

  9. JavaScript ReferenceError

    The Left Shift Assignment Operator is represented by "<<=". This operator moves the specified number of bits to the left and assigns that result to the variable. We can fill the vacated place by 0. The left shift operator treats the integer stored in the variable to the operator's left as a 32-bit binary number. This can also be explained as

  10. Is this correct syntax for setting a value?

    What is wrong with this? I keep getting the error, "Invalid left-hand in assignment." I am trying to set variable 76 to the ID of the 1st actor in the...

  11. : bad expression: Invalid left-hand side in assignment

    It means you're terminating your expression in the middle of it, causing the string concatenation operators to be seen on the left-hand side of an expression (i.e. the " + 5; + bitthe semi-colon terminates the current expression, which starts a new expression with the string concatenation operator). You're also missing some quotes and string ...

  12. {solved} ReferenceError: Invalid left-hand side in assignment

    In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.

  13. Errors: Invalid Assignment Left-hand Side

    SyntaxError: invalid assignment left-hand side. The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. For example, a single = sign was used instead of == or ===.

  14. Invalid left-hand side in assignment error but still works #3801

    I'm sure that makes it more clear what the issue is. If you want one way binding the set, use @change/@input if you want one way binding the value use :value. Could even just make total a computed value if it's used in multiple places, otherwise just bput the computation expression directly in the value binding.

  15. Error, invalid left hand side in assignment

    Question: Error, invalid left hand side in assignment Tags are words are used to describe and categorize your content. Combine multiple words with dashes(-), and seperate tags with spaces.

  16. SyntaxError: Invalid left-hand side in assignment #846

    Describe the bug. Looks like the tool doesn't play nice when you have an .env variable in the same folder you run serverless.I understand there's a way of passing environment variables to the script but for people coming in trying to deploy their existing apps that already use this form of passing parameters might have a bad experience with the tool.

  17. Invalid left-hand side in assignment Javascript

    is treated as: ( (xmlhttp.readyState == 4 && xmlhttp.status) = 200) The left hand side isn't a variable or a property, so you can't assign to it. You don't really want to assign to it though. You are trying to compare and you made a typo. xmlhttp.status = 200 should be xmlhttp.status == 200. edited Dec 19, 2016 at 10:55.

  18. Failed to compile: Syntax Error: Invalid left-hand side in assignment

    I working on an app where I have to receive data from back which contains userdetail object. I want to assign a current accessToken to the userdetail object in my code: useEffect(() => { ...

  19. r

    Looks like you are overwriting yearly.users from the first statement. When you do the first summarise, it loses the structure of the group_by needed to do the next one. Change name of the output from summarize to something else.