SyntaxError: Assigning to rvalue in JavaScript is one of the most common error messages you will encounter when working with this language. This error has numerous causes, and we cannot list all of them. However, this article will list and explain the main causes.
What is rvalue?
Lvalue and rvalue are the left and right sides of the assignment operator, respectively.
The “Assigning to rvalue” error indicates that something is wrong with your assignment statement. We cannot assign the expression on the right to the expression on the left.
Why does the SyntaxError: Assigning to rvalue in JavaScript appear on the console?
The “SyntaxError: Assigning to rvalue” error occurs in JavaScript frameworks or libraries. For instance, Vue, Pug,… In pure JavaScript, the “SyntaxError: Assigning to rvalue” corresponds to the error “SyntaxError: Invalid left-hand side in assignment“. The most common cause is using a single equal sign in a conditional statement. Look at the sample code below to understand more about this cause.
if ('learnshareit' = 'learnshareit') { console.log('Yes!'); }
Error in JavaScipt ES6:
SyntaxError: Invalid left-hand side in assignment
Error in JavaScript frameworks or libraries(Vue, Pug,…):
SyntaxError: Assigning to rvalue
This error also occurs when a value is assigned to a JS DOM attribute that does not exist. Like this:
const h1 = document.getElementById("heading-primary"); h1.style.background-color = 'red'; // This code will return a SyntaxError
Error in JavaScipt ES6:
SyntaxError: Invalid left-hand side in assignment
Error in JavaScript frameworks or libraries(Vue, Pug,…):
SyntaxError: Assigning to rvalue
How to fix this error?
Using comparison operators in conditional statements
To avoid this error, use comparison operations (==, ===, !=, !==
) instead of the assignment (=
). Because the value being passed to the if statement is a Boolean, comparison operators always return Boolean values.
// Make sure you're using == instead of = if ('learnshareit' == 'learnshareit') { console.log('Yes!'); }
Output:
Yes!
Using a code editor with the spell checker
SyntaxError occurs because our code contains a syntax error, usually caused by typos. You can avoid this error by using code editors that include spell checkers, such as VScode, WebStorm, etc.
Take a look at the two images below:


These two images are taken from VS code and WebStorm. As you can see, the code snippets that can cause syntax errors are clearly highlighted. All you have to do now is edit the highlighted code.
And here is the correct syntax:
const h1 = document.getElementById("heading-primary"); // Use the correct name of the attribute h1.style.backgroundColor = "red";
Summary
We’ve just discussed two common causes of the SyntaxError: Assigning to rvalue in JavaScript and how to avoid it. You can use any code editor or IDE you want, not just VScode or WebStorm. Hopefully, you found this article useful.
Have a nice day!
Maybe you are interested:
- SyntaxError: Unexpected token ‘export’ in JavaScript
- “SyntaxError: Illegal return statement” in JavaScript
- SyntaxError: Illegal break statement in JavaScript

Hi, I’m Cora Lopez. I have a passion for teaching programming languages such as Python, Java, Php, Javascript … I’m creating the free python course online. I hope this helps you in your learning journey.
Name of the university: HCMUE
Major: IT
Programming Languages: HTML/CSS/Javascript, PHP/sql/laravel, Python, Java