How to fix jslint Sub-exposure of '&&' should be wrapped in a parens error

I put everything in parentheses, but the code below still causes an error in jslint:

Problem at line 5 character 104: The '&&' subexpression should be wrapped in parens. if ((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== n... 

How to fix?

 "use strict"; function t() { var c1, c2; if (((typeof (c1)) === 'string') && ((typeof (c2)) === 'string') && (c1 !== null) && (c2 !== null) && ((c1.trim()) === '') || ((c2.trim()) !== '')) { return; } } 
+4
source share
3 answers

He complains about the if(a && b && c || d) form if(a && b && c || d) because (I suppose) it does not immediately become clear whether priority will be && or || . Correct it so that it looks like if(a && b && (c || d)) and it will stop complaining.

+6
source

I think he wants this:

  if (((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== null) && (c2 !== null)) && ((c1.trim()) === '') || ((c2.trim()) !== '')) { 

wrap the 4 and-expressed expressions to the left of && at 100.

0
source

I am sure you need the following :

 function t() { var c1, c2; if (typeof c1 === 'string' && typeof c2 === 'string' && c1 !== null && c2 !== null && (c1.trim() === '' || c2.trim() !== '')) { return; } } 

Not everyone knows the priority of logical logic, so they want you to wrap c1.trim() || c2.trim() c1.trim() || c2.trim() in parentheses so that they understand how they work.

As a side note, I find it ridiculous that jslint wants spaces between my operators and my operands. I think it is much clearer when there is no place.

0
source

All Articles