Home javascript JSLINT error - Expected An Assignment or Function Call and Instad Saw...

JSLINT error – Expected An Assignment or Function Call and Instad Saw An Expression

Author

Date

Category

When trying to fail with JSLINT, the following code:

entry.object.var? json_obj.var = entry.object.var: json_obj.var = "";

I get the following error:

Expected An Assignment or Function Call and Instad Saw An Expression

Here I’m trying to do the following: When undefined in Entry.Object.var assign a value to JSON, or an empty field.

Questions:

  1. Is it possible to do it more beautiful?
  2. how to correct this warning? Tried
    / * JSLINT EXPR: True * / But I get a mistake
    undexpected 'Expr'.

Answer 1, Authority 100%

The fact is that the ternary operator returns the value, JSLINT expects that you assign this value of some variable, but this does not happen. Ideologically more correct in such cases not to wise and use if-else.

In your case, it is customary to use something like:

json_obj.var = entry.object.var || "";

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions