Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerous misuse of bitwise & #23

Open
JohnWTMurray opened this issue Jan 30, 2024 · 0 comments
Open

Numerous misuse of bitwise & #23

JohnWTMurray opened this issue Jan 30, 2024 · 0 comments

Comments

@JohnWTMurray
Copy link

if ((lastActiveWord != null) & (activeWord==null)) {

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant