sabrina-aip / spellcheck

a very silly spelling bee game
75 stars 39 forks source link

Numerous misuse of bitwise & #23

Open JohnWTMurray opened 8 months ago

JohnWTMurray commented 8 months ago

https://github.com/sabrina-aip/spellcheck/blob/340c2c47d342f24a776acd71cc0c7ebb6bd2f328/assets/scripts/practice.js#L130

This is one of multiple instances of the 'bitwise and' operator being used where the 'logical and' operator should have been used.

bitwise AND: & logical AND: &&

Logical AND (&&) takes the expression before it and the expression after it (both expressions should be booleans), combining to a larger expression that evaluates to a boolean. This boolean is true if both expressions fed to it are true. Since the two expressions fed to it use comparative operators (==, !=) they evaluate to booleans.

Bitwise AND is not evaluating the total expression to a boolean, but a number that happens to be truthy, so the code is working for the wrong reason.