Your SlideShare is downloading. ×
0
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Javascript comparison and logical operators
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Javascript comparison and logical operators

1,221

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,221
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JAVASCRIPT COMPARISON AND LOGICAL OPERATORSBENJAMIN B. ESGUERRA MEMORIAL NATIONAL HIGH SCHOOL
  • 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. 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. EXAMPLE<html><body><script>var x= 10var y= 2var z= (x>y);confirm("Is "+x+" greaterthan "+y+" ?");alert(""+z+"");</script></body></html>
  • 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. 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. <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. 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. <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. 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

×