AND & OR Operators Precedence


Are you still sure that && and and is the same operators? Look at this:


a = true && false

a

=> false


a = true and false

a

=> true

The same situation could be reproduced for || and or. Why? The answer lies in Ruby Operator Precedence.

The first example can be represented as:


a = (true && false)

Second:


(a = true) and false

Thanks to Igor Alexandrov


51bd391e 99d9 4411 9c88 43616b535df1 rectangle 400 x
Alexander
Budchanov

Backend Developer at JetRockets