Tuesday, 15 October 2013

Javascript Operators

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:

OperatorEnglishExample
+Addition2 + 4
-Subtraction6 - 2
*Multiplication5 * 3
/Division15 / 3
%Modulus43 % 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


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.

OperatorEnglishExampleResult
==Equal Tox == yfalse
!=Not Equal Tox != ytrue
<Less Thanx < ytrue
>Greater Thanx > yfalse
<=Less Than or Equal Tox <= ytrue
>=Greater Than or Equal Tox >= yfalse

C

No comments:

Post a Comment