English
German

Javascript Operators

JavaScript Operators

Operators in JavaScript are very similar to operators that appear in other programming languages. The definition of an operator is a symbol that is used to perform an operation. Most often these operations are arithmetic (addition, subtraction, etc),.


JavaScript Arithmetic Operator

Operator English Example
+ Addition 2 + 2
- Subtraction 6 - 4
* Multiplication 15 * 3
/ Division 55 / 5
% Modulus 49 % 7

Modulus % may be a new operation to you, but it's just a special way of saying "finding the remainder". When you perform a division like 15/3 you get 5, exactly. However, if you do 43/10 you get an answer with a decimal, 4.3. 10 goes into 40 four times and then there is a leftover. This leftover is what is returned by the modulus operator. 43 % 10 would equal 3.


JavaScript Operator Example with Variables

Performing operations on variables that contain values is very common and easy to do. Below is a simple script that performs all the basic arithmetic operations.

Javascript Operator Example:

<body>
<script type="text/JavaScript">
<!--
var two = 3
var ten = 10
var linebreak = "<br />"

document.write("three plus ten = ")
var result = three + 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>
 


Javascript Comparison Operators

Comparisons are used to check the relationship between variables and/or values. A single equal sign sets a value while a double equal sign (==) compares two values. Comparison operators are used inside conditional statements and evaluate to either true or false. We will talk more about conditional statements in the upcoming 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

Javascript Tutorial,Javascript Operators, Javascript Operators example, learn Javascript Operators,explain example Javascript Operators online free training Javascript Tutorial, Javascript Tutorial example, learn Javascript Operators, online tutorial, download tutorial, Javascript Tutorial books, Javascript Tutorial videos, live videos Javascript Tutorial, learn Javascript Tutorial, Javascript Tutorial topic Javascript Operators, live training Javascript Tutorial, download free tutorial