Wednesday, April 25, 2018

JavaScript Operators

Arithmetic Operators

OperatorDescriptionExampleResult
+Addition2+24
-Subtraction5-23
*Multiplication4*520
/Division15/5
5/2
3
2.5
%Modulus. Returns the remainder after the first divisionExample 1:
5/2 results in 2, remainder 1
Example 2:
10/8 results in 1, remainder 2
5%2
10%8
1
2
++Incrementx=5
x++
x=6
--Decrementx=5
x--
x=4


Comparison Operators

OperatorDescriptionExample
==is equal to5==8 returns false
!=is not equal5!=8 returns true
>is greater than5>8 returns false
<is less than5<8 returns true
>=is greater than or equal to5>=8 returns false
<=is less than or equal to5<=8 returns true


Assignment Shorthand Operators

OperatorExampleIs The Same As
+=x+=yx=x+y
-=x-=yx=x-y
*=x*=yx=x*y
/=x/=yx=x/y
%=x%=yx=x%y


Logical Operators

OperatorDescriptionExample
&&andx=6
y=3(x < 10 && y > 1) returns true
||orx=6
y=3(x==5 || y==5) returns false
!notx=6
y=3x != y returns true


String Operator

A string is most often a text, for example "Hello World!". To stick two or more string variables together, use the + operator.
txt1="What a very"
txt2="nice day!"
txt3=txt1+txt2 
The variable txt3 now contains "What a verynice day!".
To add a space between two string variables, insert a space into the expression, OR in one of the strings.
txt1="What a very"
txt2="nice day!"
txt3=txt1+" "+txt2
or
txt1="What a very "
txt2="nice day!"
txt3=txt1+txt2
The variable txt3 now contains "What a very nice day!".

No comments:

Computer Terms

The termination of the process due to a program or system fault      -      Abend(abnormal ending) To terminate a process before completion....