Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript order of evaluation

Came across this JS snippet, and I honestly have NO idea of what order things are being evaluated in... Any ideas? Parentheses would be helpful...

return point[0] >= -width / 2 - allowance &&
       point[0] <= width / 2 + allowance && 
       point[1] >= -height / 2 - allowance && 
       point[1] <= height / 2 + allowance;
like image 360
whatsgoingon Avatar asked Apr 01 '11 13:04

whatsgoingon


1 Answers

https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence

The relavant operators go in this order: unary negation, division, addition/subtraction, relational (>=, <=), logical and.

return (point[0] >= ((-width / 2) - allowance))
    && (point[0] <= ((width / 2) + allowance))
    && (point[1] >= ((-height / 2) - allowance))
    && (point[1] <= ((height / 2) + allowance))
like image 122
mcrumley Avatar answered Sep 29 '22 16:09

mcrumley