Javascript Operators
Javascript arithmetic Operators
Javascript Assignment operators
the + operator used on strings
adding strings and numbers
Javascript arithmetic operators
Operator Description
+ Addition
_ Sustraction
* Multiplication
/ Division
% Modules(division remainder)
++ Increment
-- Deccrement
Javascript Assignment Operators
Operator Example Same As
= x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y
The + Operator Used on Strings
The + operator also can be used to concatenate string variable or text values together
txt1="what a very";
txt2="nice day";
txt3="txt1+txt2";
After the execution of the preceding statements, the variable txt3 contains "what a verynice day"
to add a space between the two strings, insert a space into one of the string
txt1="what a very ";
txt2="nice day";
txt3=txt1+txt2;
or insert a space into the expression:
txt1="what a very";
txt2="nice day";
txt3="txt1"+" "+"txt2";
result "what a very nice day"
Adding Strings and Numbers
If you add a stirng and number the result will be string!
<html>
<body>
<script type="text/javascript">
x=5+5;
document.write(x);
document.write("<br/>");
x="5"+"5";
document.write(x);
document.write("<br/>");
x=5+"5";
document.write(x);
document.write("<br/>");
x="5"+5;
document.write(x);
document.write("<br/>");
</script>
<p> the rule is: If you add a number and a string, the result will be a string</p>
</body>
</html>
No comments:
Post a Comment