FAQ: Conditional Statements - Logical Operators

When we declare a variable with var, let or const the interpreter is expecting one of two things:

  1. a semi-colon; the variable is declared but not defined
  2. an assignment operator (=); variable is declared and defined

In the latter case we would be assigning a value.

let a = 6

I see and, or, and not. Easy enough to follow. Is there a logical operator for “exclusive or”?

Only in the Bitwise operators, ^.

1 Like

Hi guys!! I wanted to give you a resource that I found really useful when learning C++ and also works just the same is JS. Just for you to make more sense of these logical operators:

0 - false
1 - true

I’m wondering if it is possible to adopt logical operators more than once in a sentence. Something like:

if (a || b || c ||d) {…

or even…

if (a || (b && c) || d) {…,

if (a && b &&c && d) {…
etc…

Not sure it makes some sense at all… thanks!

All of the above is valid, but we should always be looking for ways to make the logic as unconvoluted as possible. Be sure that precedence is well understood, as well. We should also be aware of short-circuiting.