Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OR and AND operator confusion in Javascript

I was coding along Colt Steele’s Web developer bootcamp. This is the original file [link] (https://github.com/tielushko/The-Web-Developer-Bootcamp/commit/4e5691d998374da5551d853752a5812a09d8d4c4) I was confused on line 5, while loop on line 5 continues as long as we don’t type "quit" or "q". It requires only one thing "quit" or "q" to close the loop, when I type either "quit" or "q" loop closes. Only one thing to close the loop ("quit" or "q") But I read that AND need both conditions in order to be true. Isn’t it ? And when I use || instead of && it behaves oddly. Can anyone explain plz? Thank you in advance.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If it helps you to understand, you can rewrite it from AND to OR:

while (command != "quit" && command != "q") {
  // do job
}

is equivalent to

while (!(command === "quit" || command === "q")) {
  // do job
}

https://en.wikipedia.org/wiki/De_Morgan%27s_laws

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading