Hi i love using “&&” as “if”.
Example:
if(a==b){ console.log(a); }
its the same as:
a==b && console.log(a);
The Code runs fawless. But i allways got these ugly error messages.
Am i doing something wrong?
EDIT:
Sometimes i got the same error when i use “? :” as “if else”
if(a==b){ console.log(a); } else { console.log(b); }
its the same as:
a==b ? console.log(a) : console.log(b);
It’s a jshint (linter) warning. Your code is needlessly tricky, it is telling you that. The code works, it is just ambiguous, if you use if
it will not warn.
The linter is expecting the conditional to be an if, and the ternary to either be an if/else or be assigned to a variable. I get that the end result of your code is the same as that, and it is very tempting to write code like that, but it is code golf, it makes it difficult to read for people who aren’t you.
1 Like
Ermm, I would assume it could be an issue with the linter. Although saying that I would suggest you to use the IF ELSE statements as they are instead of trying to make the code look complicated?