Logical Operators in JavaScript

Logical operators are another type of operators in JavaScript which are used to perform logical operations like AND(&&), OR(||), NOT(!). Logical Operators in JavaScript are used to combine two or more boolean expressions and return a single boolean value. They are used to determine the logic between variables or values. There are three types of logical operators in JavaScript -

Types of Operators

  1. Logical AND (&&)
  2. Logical OR (||)
  3. Logical NOT (!)
  • && (AND)

    AND (&&) operator returns true only when both the statements condition given are the same, else returns false. It checks both the given condition and displays true only if both conditions are same, else false.

    For example:

X = (5==6 && 7==8)
returns false as both the given conditions do not match with each other.
  • || (OR)

    OR (||) operator returns true when anyone of the statements condition given are the same, else returns false.

    For example:

X = (5==6 || 7==8)
  • ! (NOT)

    NOT (!) is a unary operator that produces the negative/opposite if the given operand. Given any condition, the ! operator checks the given condition, converts it into the opposite condition, then returns the output.

    For example:

a = true;
  b=!a;
  console.log(b);
Output:

false

since the given input is true and the opposite of true is false.

Conclusion

In this article, we have discussed about the logical operators in JavaScript. You’ve read about the types of logical operators, followed by well-explained examples. Moving ahead, we’ll be reading about other types of operators which are well-explained. As a beginner, you need to focus more on the fundamentals of JavaScript to hold a string grip on it.


Learn via Video Course

Javascript(English) Logo

Javascript(English)

72966

3 hrs