Upcoming SlideShare
×

# Javascript comparison and logical operators

1,545 views

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,545
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
4
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Javascript comparison and logical operators

1. 1. JAVASCRIPT COMPARISON AND LOGICAL OPERATORSBENJAMIN B. ESGUERRA MEMORIAL NATIONAL HIGH SCHOOL
2. 2. JavaScript Comparison and LogicalOperators  Comparison and Logical operators are used to test for true or false.  Comparison Operators are used in logical statements to determine equality or difference between variables or values.  Logical Operators are used to determine the logic between variables or values.
3. 3. COMPARISON OPERATORS Given that x=5, the table below explains the comparison operators.Operator Description Comparing Returns x==8 FALSE == is equal to x==5 TRUE x==="5" FALSE is exactly equal to (value and type) x===5 TRUE != is not equal x!=8 TRUE x!=="5" TRUE !== is not equal (neither value or type) x!==5 FALSE > is greater than x>8 FALSE < is less than x<8 TRUE >= is greater than or equal to x>=8 FALSE <= is less than or equal to x<=8 TRUE
4. 4. EXAMPLE<html><body><script>var x= 10var y= 2var z= (x>y);confirm("Is "+x+" greaterthan "+y+" ?");alert(""+z+"");</script></body></html>
5. 5. EXAMPLE<html><body><script>var x= parseFloat(prompt(“Enter the first value”,””));var y= parseFloat(prompt(“Enter the second value”,””));confirm(“Is”+x+”var z= (x>y);alert(""+z+"");</script></body></html>
6. 6. LOGICAL OPERATORSGiven that x=6 and y=3 the table below explains the logicaloperators.Operator Description Comparing Returns &&(ampersand) and (x<10 && y>1) TRUE || or (x==5||y==5) FALSE ! not !(x==y) TRUE
7. 7. <script>var x= 10var y= 2var z= (x>y && y<x)confirm("Is "+x+" greater than "+y+" ?, and "+y+" is less than "+x+" ?");alert(""+z+"");</script></body></html>
8. 8. CONDITIONAL OPERATOR JavaScript also contains a conditional operator that assigns a value to a variable based on some conditions.SYNTAX:variable name= (condition)? value1:value2Example:If the variable age is value below 18, the value of the variable voteable will be “Too young, otherwise the value of votaable will be “Old enough”var age= 18var voteable= (age<18)? “Too young”:”Old enough”
9. 9. <html><body><script>var x= prompt("Who created the JavaScript? "," ");var y= “Brendan Eich"var z= (x==y)?"Correct": "Wrong";alert(""+z+"");document.write("Correct Answer: "+y+"");</script></body></html>
10. 10. Assign/SeatworkCreate the JavaScript source codeCOMPARISON50 is less than 68LOGICAL50 is equal to 68 and 68 is equal to 50CONDITIONALWhat is the first calculating device? Abacus or Comptometer?Condition: Congratulation! And Try Again