• Register
0 votes

Problem :

I am very new to React and so facing this error

expected an assignment or function call and instead saw an expression no-unused-expressions

by (6.9k points)

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

This error comes up because you have put the bracket of return on the next line. This is a common mistake if you are familier with js without semicolons and you use a style where you put opened braces on the next line.

But the nnterpreter thinks that you return undefined and will not check your next line. So the return operator thing.

So to get rid of this issue you need to put your opening bracket on the same line with the return.

by (38.6k points)
0 votes

The “expected an assignment or function call and instead saw an expression” error encounters in javascript when an expression return value with no effect.


In the following example, we have a conditional statement that has to evaluate true but has no effect on the program.

var x =1;

x ====1; //Evaluates to be “true”.

Another example:

var x = 5;

var y = 3 * 7;

var z = “cake” .length * 9;


The values on the right-hand side of the assignment operator are called expression. The expressions can not stand alone. The warning message can occur that you have forgotten the variables that would normally assign that the expressions value tp.

Function call:

A function call is something like console.log(“HI”). This function call also called an expression.

Missing Semicolons:

In some cases semicolons can also be omitted. But it is suggested to put them wherever the yellow warning sign says that a semicolon is missing. You can remove them later when you understand exactly under which conditions these semicolons can be omitted. If the removal of semicolon does not produce a warning, then it means that the semicolon does not belong at that place.


Semicolons in the wrong places can create bugs that are hard to find.

by (3.9k points)

Related questions

0 votes
1 answer
0 votes
2 answers