• Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free
  • 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 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.

What went wrong?

There was an unexpected assignment somewhere. This might be due to a mismatch of a assignment operator and a comparison 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 a comparison operator ("=="), and for the string concatenation, the plus ("+") operator is needed.

  • Assignment operators
  • Comparison operators
  • JavaScript basics
  • JavaScript first steps
  • JavaScript building blocks
  • Introducing JavaScript objects
  • Introduction
  • Grammar and types
  • Control flow and error handling
  • Loops and iteration
  • Expressions and operators
  • Numbers and dates
  • Text formatting
  • Regular expressions
  • Indexed collections
  • Keyed collections
  • Working with objects
  • Details of the object model
  • Using promises
  • Iterators and generators
  • Meta programming
  • JavaScript modules
  • Client-side web APIs
  • A re-introduction to JavaScript
  • JavaScript data structures
  • Equality comparisons and sameness
  • Inheritance and the prototype chain
  • Strict mode
  • JavaScript typed arrays
  • Memory Management
  • Concurrency model and Event Loop
  • References:
  • AggregateError
  • ArrayBuffer
  • AsyncFunction
  • BigInt64Array
  • BigUint64Array
  • Float32Array
  • Float64Array
  • GeneratorFunction
  • InternalError
  • ReferenceError
  • SharedArrayBuffer
  • SyntaxError
  • Uint16Array
  • Uint32Array
  • Uint8ClampedArray
  • WebAssembly
  • decodeURI()
  • decodeURIComponent()
  • encodeURI()
  • encodeURIComponent()
  • parseFloat()
  • Arithmetic operators
  • Bitwise operators
  • Comma operator
  • Conditional (ternary) operator
  • Destructuring assignment
  • Function expression
  • Grouping operator
  • Logical operators
  • Nullish coalescing operator
  • Object initializer
  • Operator precedence
  • Optional chaining
  • Pipeline operator
  • Property accessors
  • Spread syntax
  • async function expression
  • class expression
  • delete operator
  • function* expression
  • in operator
  • new operator
  • void operator
  • async function
  • for await...of
  • function declaration
  • import.meta
  • try...catch
  • Arrow function expressions
  • Default parameters
  • Method definitions
  • Rest parameters
  • The arguments object
  • Class fields
  • constructor
  • Error: Permission denied to access property "x"
  • InternalError: too much recursion
  • RangeError: argument is not a valid code point
  • RangeError: invalid array length
  • RangeError: invalid date
  • RangeError: precision is out of range
  • RangeError: radix must be an integer
  • RangeError: repeat count must be less than infinity
  • RangeError: repeat count must be non-negative
  • ReferenceError: "x" is not defined
  • ReferenceError: assignment to undeclared variable "x"
  • ReferenceError: can't access lexical declaration "x" before initialization
  • ReferenceError: deprecated caller or arguments usage
  • ReferenceError: reference to undefined property "x"
  • SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated
  • SyntaxError: "use strict" not allowed in function with non-simple parameters
  • SyntaxError: "x" is a reserved identifier
  • SyntaxError: JSON.parse: bad parsing
  • SyntaxError: Malformed formal parameter
  • SyntaxError: Unexpected token
  • SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
  • SyntaxError: a declaration in the head of a for-of loop can't have an initializer
  • SyntaxError: applying the "delete" operator to an unqualified name is deprecated
  • SyntaxError: for-in loop head declarations may not have initializers
  • SyntaxError: function statement requires a name
  • SyntaxError: identifier starts immediately after numeric literal
  • SyntaxError: illegal character
  • SyntaxError: invalid regular expression flag "x"
  • SyntaxError: missing ) after argument list
  • SyntaxError: missing ) after condition
  • SyntaxError: missing : after property id
  • SyntaxError: missing ; before statement
  • SyntaxError: missing = in const declaration
  • SyntaxError: missing ] after element list
  • SyntaxError: missing formal parameter
  • SyntaxError: missing name after . operator
  • SyntaxError: missing variable name
  • SyntaxError: missing } after function body
  • SyntaxError: missing } after property list
  • SyntaxError: redeclaration of formal parameter "x"
  • SyntaxError: return not in function
  • SyntaxError: test for equality (==) mistyped as assignment (=)?
  • SyntaxError: unterminated string literal
  • TypeError: "x" has no properties
  • TypeError: "x" is (not) "y"
  • TypeError: "x" is not a constructor
  • TypeError: "x" is not a function
  • TypeError: "x" is not a non-null object
  • TypeError: "x" is read-only
  • TypeError: "x" is not iterable
  • TypeError: More arguments needed
  • TypeError: Reduce of empty array with no initial value
  • TypeError: X.prototype.y called on incompatible type
  • TypeError: can't access dead object
  • TypeError: can't access property "x" of "y"
  • TypeError: can't assign to property "x" on "y": not an object
  • TypeError: can't define property "x": "obj" is not extensible
  • TypeError: can't delete non-configurable array element
  • TypeError: can't redefine non-configurable property "x"
  • TypeError: cannot use "in" operator to search for "x" in "y"
  • TypeError: cyclic object value
  • TypeError: invalid "instanceof" operand "x"
  • TypeError: invalid Array.prototype.sort argument
  • TypeError: invalid arguments
  • TypeError: invalid assignment to const "x"
  • TypeError: property "x" is non-configurable and can't be deleted
  • TypeError: setting getter-only property "x"
  • TypeError: variable "x" redeclares argument
  • URIError: malformed URI sequence
  • Warning: -file- is being assigned a //# sourceMappingURL, but already has one
  • Warning: 08/09 is not a legal ECMA-262 octal constant
  • Warning: Date.prototype.toLocaleFormat is deprecated
  • Warning: JavaScript 1.6's for-each-in loops are deprecated
  • Warning: String.x is deprecated; use String.prototype.x instead
  • Warning: expression closures are deprecated
  • Warning: unreachable code after return statement
  • JavaScript technologies overview
  • Lexical grammar
  • Enumerability and ownership of properties
  • Iteration protocols
  • Transitioning to strict mode
  • Template literals
  • Deprecated features
  • DSA with JS - Self Paced
  • A to Z Guide
  • Free JS Course
  • Cheat Sheet
  • Interview Questions
  • JS Formatter
  • Web Technology

error invalid assignment left hand side detail invalid assignment left hand side

  • Explore Our Geeks Community
  • JavaScript SyntaxError - Illegal character
  • JavaScript TypeError - Invalid assignment to const "X"
  • JavaScript TypeError - Invalid 'instanceof' operand 'x'
  • JavaScript TypeError - Invalid Array.prototype.sort argument
  • JavaScript ReferenceError - Can't access lexical declaration`variable' before initialization
  • JavaScript TypeError - Setting getter-only property "x"
  • JavaScript Warning - Date.prototype.toLocaleFormat is deprecated
  • JavaScript SyntaxError - Return not in function
  • JavaScript ReferenceError - Assignment to undeclared variable
  • JavaScript TypeError - Property "X" is non-configurable and can't be deleted
  • JavaScript SyntaxError: Unterminated string literal
  • JavaScript SyntaxError - Identifier starts immediately after numeric literal
  • JavaScript SyntaxError - Invalid regular expression flag "x"
  • JavaScript SyntaxError - Missing ) after argument list
  • JavaScript SyntaxError - Missing ) after condition
  • JavaScript SyntaxError - Missing ':' after property id
  • JavaScript SyntaxError - Missing ; before statement
  • JavaScript SyntaxError - Missing = in const declaration
  • JavaScript SyntaxError - Missing ] after element list

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

  • shobhit_sharma
  • vishalkumar2204
  • JavaScript-Errors
  • Web Technologies

Please write us at [email protected] to report any issue with the above content

Improve your Coding Skills with Practice

 alt=

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

avatar

Last updated: Feb 16, 2023 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 © 2023 Borislav Hadzhiev

  • Debug Wordle
  • Book a Demo
  • Start For Free

question-mark

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught ReferenceError: Invalid left-hand side in assignment

I get the following clientside errors using Node 8 with either yarn 0.24.6 or NPM 5:

2017-06-13 at 10 23 pm

This is a fresh build with no modification to config.

Issue Analytics

  • Created 6 years ago
  • Comments: 11 (5 by maintainers)

Top GitHub Comments

Ah. Sorry. I did but then switched to a different branch and did not merge this in.

@illepic Thanks. Could you do git pull and try again now?

Top Results From Across the Web

Top related medium post, top related stackoverflow question, troubleshoot live code, top related reddit thread, top related hackernoon post, top related tweet, top related dev.to post, top related hashnode post, knex seed for postgres.

IMAGES

  1. javascript

    error invalid assignment left hand side detail invalid assignment left hand side

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

    error invalid assignment left hand side detail invalid assignment left hand side

  3. ERROR: Invalid assignment target:v-model中使用可选链操作符报错。-CSDN博客

    error invalid assignment left hand side detail invalid assignment left hand side

  4. Error: Invalid left-hand side in assignment

    error invalid assignment left hand side detail invalid assignment left hand side

  5. Invalid Assignment error

    error invalid assignment left hand side detail invalid assignment left hand side

  6. Uncaught syntaxerror invalid left-hand side in assignment

    error invalid assignment left hand side detail invalid assignment left hand side

VIDEO

  1. SE03-08 Custom Exceptions

  2. #5

  3. How to Deal With The Invalid Traffic BS

  4. Assignment front page//side border//Project work

  5. python r-value and l-value XIcls CS

  6. Doodle

COMMENTS

  1. What Does “Invalid DIM” on a TI-83 Mean?

    “ERR:INVALID DIM” is an error message that comes up when one or more of the calculator’s “STAT PLOTS” are set to “on” but there are no values or incomplete values in the “STAT” lists. It can also mean the user entered the wrong type of data...

  2. Where Is Area Code 547?

    The area code 547 is not currently assigned to any location in the world and is considered invalid within the international phone system. As of September 2014, all area codes between 545 and 550 are unassigned and invalid.

  3. Troubleshooting Common Issues When Setting up an Email Account

    Creating an email account is a relatively simple process, but it can sometimes be accompanied by various issues that can cause frustration and inconvenience. One of the most common issues users face when creating an email account is enterin...

  4. SyntaxError: invalid assignment left-hand side

    The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere.

  5. Что означает ошибка ReferenceError: Invalid left-hand side in

    Как исправить ошибку ReferenceError: Invalid left-hand side in assignment. Скорее всего, вы используете присваивание вместо сравнения. Это

  6. ReferenceError: Invalid left-hand side in assignment

    Common reasons for the error: use of assignment ( = ) instead of equality ( == / === ); assigning to result of function foo

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

  8. JavaScript ReferenceError

    This JavaScript exception invalid assignment left-hand side occurs if there is a wrong assignment somewhere in code.

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

  10. Ошибка:"invalid assignment left-hand side"

    При выполнении такого кода: if(now.getDate() > 25 && now.getDate() =< 31) возникает "invalid assignment left-hand side". Скажите почему.

  11. JavaScript ReferenceError

    The Invalid Assignment Left-Hand Side Error Explained. The name of this error indicates that this error is caused by a faulty or buggy assignment statement. The

  12. Assignment Error in Javascript: Left-hand side is Invalid

    The JavaScript exception "invalid assignment left-hand side" happens when an unexpected assignment occurs. This can happen, for instance, when a

  13. Uncaught Referenceerror Invalid Left Hand Side In Assignment

    to update the input range on some custom controls and am getting an error that reads Uncaught, ReferenceError: Invalid left-hand side in assignment $(document).

  14. Uncaught ReferenceError: Invalid left-hand side in assignment

    I get the following clientside errors using Node 8 with either yarn 0.24.6 or NPM 5: Uncaught ReferenceError: Invalid left-hand side in assignment vendor_w.