0
Upcoming SlideShare
×

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.
Standard text messaging rates apply

# Javascript comparison and logical operators

1,221

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,221
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
2
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. JAVASCRIPT COMPARISON AND LOGICAL OPERATORSBENJAMIN B. ESGUERRA MEMORIAL NATIONAL HIGH SCHOOL
• 2. JavaScript Comparison and LogicalOperators &#xF097; Comparison and Logical operators are used to test for true or false. &#xF097; Comparison Operators are used in logical statements to determine equality or difference between variables or values. &#xF097; 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 &gt; is greater than x&gt;8 FALSE &lt; is less than x&lt;8 TRUE &gt;= is greater than or equal to x&gt;=8 FALSE &lt;= is less than or equal to x&lt;=8 TRUE
• 4. EXAMPLE&lt;html&gt;&lt;body&gt;&lt;script&gt;var x= 10var y= 2var z= (x&gt;y);confirm("Is "+x+" greaterthan "+y+" ?");alert(""+z+"");&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
• 5. EXAMPLE&lt;html&gt;&lt;body&gt;&lt;script&gt;var x= parseFloat(prompt(&#x201C;Enter the first value&#x201D;,&#x201D;&#x201D;));var y= parseFloat(prompt(&#x201C;Enter the second value&#x201D;,&#x201D;&#x201D;));confirm(&#x201C;Is&#x201D;+x+&#x201D;var z= (x&gt;y);alert(""+z+"");&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
• 6. LOGICAL OPERATORSGiven that x=6 and y=3 the table below explains the logicaloperators.Operator Description Comparing Returns &amp;&amp;(ampersand) and (x&lt;10 &amp;&amp; y&gt;1) TRUE || or (x==5||y==5) FALSE ! not !(x==y) TRUE
• 7. &lt;script&gt;var x= 10var y= 2var z= (x&gt;y &amp;&amp; y&lt;x)confirm("Is "+x+" greater than "+y+" ?, and "+y+" is less than "+x+" ?");alert(""+z+"");&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
• 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 &#x201C;Too young, otherwise the value of votaable will be &#x201C;Old enough&#x201D;var age= 18var voteable= (age&lt;18)? &#x201C;Too young&#x201D;:&#x201D;Old enough&#x201D;
• 9. &lt;html&gt;&lt;body&gt;&lt;script&gt;var x= prompt("Who created the JavaScript? "," ");var y= &#x201C;Brendan Eich"var z= (x==y)?"Correct": "Wrong";alert(""+z+"");document.write("Correct Answer: "+y+"");&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
• 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