Operators in JavaScript ar terribly almost like operators that seem in alternative programming languages. The definition of associate operator may be a image that's wont to perform associate operation. most frequently these operations ar arithmetic (addition, subtraction, etc), however not forever.
Airthmetic Operator List:
| Operator | English | Example |
|---|---|---|
| + | Addition | 2 + 4 |
| - | Subtraction | 6 - 2 |
| * | Multiplication | 5 * 3 |
| / | Division | 15 / 3 |
| % | Modulus | 43 % 10 |
Modulus % could also be a replacement operation to you, however it's simply a special method of claiming "finding the remainder". after you perform a division like 15/3 you get five, exactly. However, if you are doing 43/10 you get a solution with a decimal, 4.3. ten goes into forty fourfold so there's a leftover. This leftover is what's came by the modulus operator. forty three the ten would equal three.
Javascript operator example with variables:
Performing operations on variables that contain values is extremely common and straightforward to try to to. Below may be a easy script that performs all the essential arithmetic operations.
Example Code:
<body>
<script type="text/JavaScript">
<!--
var two = 2
var ten = 10
var linebreak = "<br />"
document.write("two plus ten = ")
var result = two + ten
document.write(result)
document.write(linebreak)
document.write("ten * ten = ")
result = ten * ten
document.write(result)
document.write(linebreak)
document.write("ten / two = ")
result = ten / two
document.write(result)
//-->
</script>
</body>
Output:
two plus ten = 12
ten * ten = 100
ten / two = 5
ten * ten = 100
ten / two = 5
Comparison Operators in JavaSciript:
Comparisons ar wont to check the connection between variables and/or values. one equal sign sets a worth whereas a double equal sign (==) compares 2 values. Comparison operators ar used within conditional statements and value to either true or false. we are going to speak additional regarding conditional statements within the forthcoming lessons.
| Operator | English | Example | Result |
|---|---|---|---|
| == | Equal To | x == y | false |
| != | Not Equal To | x != y | true |
| < | Less Than | x < y | true |
| > | Greater Than | x > y | false |
| <= | Less Than or Equal To | x <= y | true |
| >= | Greater Than or Equal To | x >= y | false |
C
No comments:
Post a Comment