Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected assignment or function call: no-unused-expressions ReactJS

Tags:

reactjs

jsx

class Game extends Component  {   constructor()    {     super()     this.state = {       speed: 0     }     //firebaseInit()   }   render()   {     return      (       <div>         <h1>The Score is {this.state.speed};</h1>       </div>     )   } }  export default Game; 

I am new to React and for this code its giving this error

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

Dont understand where getting wrong, please help

like image 668
Prateek Pandey Avatar asked Oct 26 '18 17:10

Prateek Pandey


People also ask

How do you solve expected an assignment or function call and instead saw an expression no unused expressions?

js error "Expected an assignment or function call and instead saw an expression" occurs when we forget to return a value from a function. To solve the error, make sure to explicitly use a return statement or implicitly return using an arrow function.

What is no unused expressions?

An unused expression which has no effect on the state of the program indicates a logic error. For example, n + 1; is not a syntax error, but it might be a typing mistake where a programmer meant an assignment statement n += 1; instead.


1 Answers

This happens because you put bracket of return on the next line. That might be a common mistake if you write js without semicolons and use a style where you put opened braces on the next line.

Interpreter thinks that you return undefined and doesn't check your next line. That's the return operator thing.

Put your opened bracket on the same line with the return.

like image 179
Andrey Medvedev Avatar answered Sep 22 '22 18:09

Andrey Medvedev