Tuesday, June 12, 2012

Java Script Beginner Tutorial 6 : JavaScript Operators

JavaScript operators are used to perform operations on JavaScript variables. The assignment operator = is used to assign values to JavaScript variables. The arithmetic operator + is used to add values together. For example


x = 3;
y = 4;
z = x + y;


The output 'll be equal to 7. 


Arithmetic operators are used to perform arithmetic between variables and/or values. There are many arithmetic operators, we use in JavaScript, for example


+  ( used for addition),                -  ( used for subtraction ), 
*  ( used for multiplication ),        /  ( used for division ), 
%  ( used for modulus ),             ++  ( used for increment ) and 
--  ( used for decrement )


Assignment operators are used to assign values to JavaScript variables. These assignments operators can be used in JavaScript :


= ,  += ,  -= ,   *= ,   /=   and   %=


The + operator can also be used to add string variables or text values together. For example


str1 = "This is ";
str2 = "a fox";
str3 = str1 + str2;


The output 'll be "This is a fox."
If you add a number and a string, the result will be a string. For example 


x = "this is a string" + 10 ;


The output 'll be "this is a string10".

No comments:

Post a Comment