error solved

Fix- expected an assignment or function call and instead saw an expression


If you are getting expected an assignment or function call and instead saw an expression error, Here is a simplified version that gives the same warning:

var a, b;
a && (b = a);

This throws the error Expected an assignment or function call and instead saw an expression.

This means that you have an expression but do not assign the result to any variable. jshint doesn’t care about what the actual expression is or that there are side effects. Even though you assign something inside the expression, you are still ignoring the expression’s result.

There is another error by jslint if you care about it:

Unexpected assignment expression

This warns you that you may want to use == instead of = inside logical expressions. It’s a standard error. Therefore you are discouraged from using logical expression assignments (even though it is precisely what you want here).

Jshint/Jslint do not like misuse of shortcut evaluation of logical operator as a replacement for if statements. It assumes that if the result of an expression is not used, it probably shouldn’t be an expression.


Share on social media

//