1 / 42

Operators

Operators. Today’s Learning Goals …. Understand the purpose of JavaScript operators Explore the mathematical operators Find out about the assignment operators Understand the comparison operators Learn about the logical operators. What is an Operator?.

Télécharger la présentation

Operators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operators

  2. Today’s Learning Goals … • Understand the purpose of JavaScript operators • Explore the mathematical operators • Find out about the assignment operators • Understand the comparison operators • Learn about the logical operators

  3. What is an Operator? • A short symbol in JavaScript that performs some sort of calculation, comparison, or assignment on one or more values

  4. Types of Operators • Mathematical • Assignment • Comparison • Logical

  5. Mathematical Operators • Used for mathematical calculations • Used for • Calculating sum of numbers • Joining strings together • Dividing numbers

  6. Addition Operator (+)Variables for Addition Results <SCRIPT language = “JavaScript”> <!-- var thesum = 4 + 7; window.alert(thesum); //--> </SCRIPT>

  7. Addition Operator (+)Variables for Addition Results <SCRIPT language = “JavaScript”> <!-- var num1 = 4; var num2 = 7; var thesum = num1 + num2; window.alert(thesum); //--> </SCRIPT>

  8. Addition Operator (+)Type Conversions in Addition Calculations <SCRIPT language = “JavaScript”> <!-- var num1 = 4.73; var num2 = 7; var thesum = num1 + num2; window.alert(thesum); //--> </SCRIPT>

  9. Addition Operator (+)Type Conversions in Addition Calculations <SCRIPT language = “JavaScript”> <!-- var num1 = 4; var num2 = “7”; var thesum = num1 + num2; window.alert(thesum); //--> </SCRIPT>

  10. Subtraction Operator (-) <SCRIPT language = “JavaScript”> <!-- var num1 = 10; var num2 = 3; var theresult = num1 - num2; window.alert(theresult); //--> </SCRIPT>

  11. Multiplication Operator (*) <SCRIPT language = “JavaScript”> <!-- var num1 = 4; var num2 = 5; var theresult = num1 * num2; window.alert(theresult); //--> </SCRIPT>

  12. Division Operator (/) <SCRIPT language = “JavaScript”> <!-- var num1 = 10; var num2 = 2; var theresult = num1 / num2; window.alert(theresult); //--> </SCRIPT>

  13. Operand • Value that the operator works on

  14. Increment Operator (++)Before the Operand <SCRIPT language = “JavaScript”> <!-- var num1 = 2; var theresult = ++num1; //--> </SCRIPT>

  15. Increment Operator (++)After the Operand <SCRIPT language = “JavaScript”> <!-- var num1 = 2; var theresult = num1++; //--> </SCRIPT>

  16. Decrement Operator (--)Before the Operand <SCRIPT language = “JavaScript”> <!-- var num1 = 2; var theresult = --num1; //--> </SCRIPT>

  17. Decrement Operator (--)After the Operand <SCRIPT language = “JavaScript”> <!-- var num1 = 2; var theresult = num1--; //--> </SCRIPT>

  18. Unary Negation Operator (-) <SCRIPT language = “JavaScript”> <!-- var negnum = -3; //--> </SCRIPT>

  19. Assignment Operators • Assign a value to a variable • Do not compare two items, nor do they perform logical tests

  20. Assignment Operator (=) <SCRIPT language = “JavaScript”> <!-- var population = 150000000; //--> </SCRIPT>

  21. Add and Assign Operator (+=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; myMoney = myMoney + 1 //--> </SCRIPT>

  22. Add and Assign Operator (+=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; myMoney += 1; //--> </SCRIPT>

  23. Subtract and Assign Operator (-=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; var myBills = 800; myMoney -= myBills; //--> </SCRIPT>

  24. Multiply and Assign Operator (*=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; var multby = 2; myMoney *= multby; //--> </SCRIPT>

  25. Divide and Assign Operator (/=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; var cutPayBy = 2; myMoney /= cutPayBy; //--> </SCRIPT>

  26. Modulus and Assign Operator (%=) <SCRIPT language = “JavaScript”> <!-- var myMoney = 1000; var cutPayBy = 2; myMoney %= cutPayBy; //--> </SCRIPT>

  27. Comparison Operators • Used with conditional statements and loops to perform actions only when a certain condition is met • Return value of either true or false

  28. Is-Equal-To Operator (==)

  29. Is-Not-Equal-To Operator (!=)

  30. Is-Greater-Than Operator (>)

  31. Is-Less-Than Operator (<)

  32. Is-Greater-Than-or-Equal-To Operator (>=)

  33. Is-Less-Than-or-Equal-To Operator (>=)

  34. Logical Operators • Compare two conditional statements to see if one or more of the statements is true and to proceed accordingly • Return either true or false

  35. AND Operator (&&)

  36. OR Operator (||)

  37. NOT Operator (!)

  38. What We Learnt Today … • Understood the purpose of JavaScript operators • Explored the mathematical operators • Found out about the assignment operators • Understood the comparison operators • Learnt about the logical operators

More Related