Javascript Programming
Free

JavaScript Comparison
JavaScript Logical and Comparison Operators
JavaScript Logical and Comparison Operator are used to test for false or true.
Comparison Operator
Operator | Description |
---|---|
> | greater than |
< | less than |
== | equal to |
!= | not equal to |
>= | greater than or equal to |
<= | less than or equal to |
=== | equal value and equal type |
!== | not equal value or not equal type |
Logical Operator
Operator | Description |
---|---|
|| | or |
&& | and |
! | not |
Greater than(>) operator
Example
var num = 7 ; (num > 6) ; // This line is used for testing that num is greater than 6
Code
<!DOCTYPE html> <html> <body> <p>Click on button to testing that num is greater than 6 </p> <button onclick="myFunction()">Click Here</button> <p id="demo"></p> <script> var num = 7 ; function myFunction(){ document.getElementById("demo").innerHTML = (num > 6); } </script> </body> </html>
Output
Click on button to testing that num is greater than 6
not equal to(!=) Operator
Example
var num = 7 ; (num != 6); // This line is used for testing that num is not equal to 6
Code
<!DOCTYPE html> <html> <body> <p>Click on button to testing that num is not equal to 6 </p> <button onclick="myFunction()">Click Here</button> <p id="demo"></p> <script> var num = 7 ; function myFunction(){ document.getElementById("demo").innerHTML = (num != 6); } </script> </body> </html>
Output
Click on button to testing that num is not equal to 6
less than or equal to(<) Operator
Example
var num = 7 ; (num <= 6) ; // This line is used for testing that num is less than or equal to 6
Code
<!DOCTYPE html> <html> <body> <p>Click on button to testing that num is less than or equal to 6 </p> <button onclick="myFunction()">Click Here</button> <p id="demo"></p> <script> var num = 7 ; function myFunction(){ document.getElementById("demo").innerHTML = (num <= 6); } </script> </body> </html>
Output
Click on button to testing that num is less than or equal to 6
equal to(=) Operator
Example
var num = 7 ; (num <= 7) ; // This line is used for testing that num is equal to 7
Code
<!DOCTYPE html> <html> <body> <p>Click on button to testing that num is equal to 7 </p> <button onclick="myFunction()">Click Here</button> <p id="demo"></p> <script> var num = 7 ; function myFunction(){ document.getElementById("demo").innerHTML = (num <= 7); } </script> </body> </html>
Output
Click on button to testing that num is equal to 7
JavaScript is the programming language of the Web.All modern HTML pages are using JavaScript.This tutorial will teach you JavaScript from basic to advanced. Webclasses tutorials will help you leaning from beginning.
Course Features
- Lectures 28
- Quizzes 0
- Skill level Beginner
- Language English
- Students 24
- Certificate No
- Assessments Self