1

consider the below code I'm not able to understand the last statement -1 !== y && x.push(y) of the for loop. Any help would be appreciated.

for (var V = f.text, Q = V.length, t = 2 + Q / 30 >> 0, p = V.trim().split(/\s+/).length, 
         r = Math.sqrt(Q * b / A / 2.8) + .5 >> 0, r = Math.min(p, Math.max(1, r)), u = Q / r, v = [], p = [], x = [], y = 0; -1 !== y;) 
    y = V.indexOf(" ", y + 1), -1 !== y && x.push(y);
Ele
  • 33,468
  • 7
  • 37
  • 75
zeeeuu
  • 19
  • 4
  • 2
    I would highly suggest only trying to read *development* code, not *minified production* code, else you'll only give yourself a headache – CertainPerformance Nov 29 '18 at 02:45
  • `Array.indexOf` returns `-1` if provided value is not found in the Array. `y = V.indexOf(" ", y + 1), -1 !== y && x.push(y)` So, if there's an empty string in `V` then `y` becomes the index of that, else y becomes `-1`. Then you check if `y !== -1` and if so push that value of `y` into `x`. – CodeDraken Nov 29 '18 at 02:47
  • 1
    `&&` won't bother evaluating the right hand operand if the left one is falsy. `false && something` is `false` no matter whether `something` is `true` or `false`, so `&&` won't waste time evaluating it. So we can use `&&` for short circuiting, meaning we use `condition && statement` so that we evaluate `statement` if and only if `condition` is truthy, it's equivalent to `if(condition) { statement; }`. We use `||` for the exact opposite, we evaluate the `statement` if and only if the `condition` is falsy. – ibrahim mahrir Nov 29 '18 at 02:53
  • 1
    I was not familiar with such kind of syntax of javascript -1 !== y && x.push(y) but now I have clear understanding of this syntax. Thank you all specially ibrahim mahrir – zeeeuu Nov 29 '18 at 02:56
  • Try running these example and see what happens: **1.** `false && alert("hello")`. **2.** `true && alert("hello")`. **3.** `false || alert("hello")`. **4.** `true || alert("hello")` – ibrahim mahrir Nov 29 '18 at 02:58

0 Answers0