04. JavaScript Operators

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:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams