
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Logical Operators in JavaScript?
JavaScript supports the following logical operators. Assume variable A holds 10 and variable B holds 20, then,
Sr.No | Operator and Description |
---|---|
1 | && (Logical AND) If both the operands are non-zero, then the condition becomes true. Ex: (A && B) is true. |
2 | || (Logical OR) If any of the two operands are non-zero, then the condition becomes true. Ex: (A || B) is true. |
3 | ! (Logical NOT) Reverses the logical state of its operand. If a condition is true, then the Logical NOT operator will make it false. Ex: ! (A && B) is false. |
Example
You can try the following code to learn how to implement Logical Operators in JavaScript −
<html> <body> <script> <!-- var a = true; var b = false; var linebreak = "<br />"; document.write("(a && b) => "); result = (a && b); document.write(result); document.write(linebreak); document.write("(a || b) => "); result = (a || b); document.write(result); document.write(linebreak); document.write("!(a && b) => "); result = (!(a && b)); document.write(result); document.write(linebreak); //--> </script> <p>Set the variables to different values and different operators and then try...</p> </body> </html>
- Related Questions & Answers
- What types of logical operators are in javascript?
- What are the logical operators in Java?
- What are the logical operators in C#?
- Java Logical Operators
- Perl Logical Operators
- Python Logical Operators
- Logical Operators in C++
- What are JavaScript Operators
- What are operators in JavaScript?
- What are JavaScript Bitwise Operators?
- What are Arithmetic Operators in JavaScript?
- What are Comparison Operators in JavaScript?
- What are Assignment Operators in JavaScript?
- What are Conditional Operators in JavaScript?
- Java Regular expressions Logical operators
Advertisements