HOME  |    TRAINING  |   FREE TUTORIALS   |   JOBS
Find out more about our new RSS feed.
FREE Tutorial
OPERATORS AND JAVASCRIPT

CATEGORY
SEARCH OUR OTHER TUTORIALS

DESCRIPTION

This tutorial explains about the use of operators within JavaScript.


TUTORIAL TAKEN FROM COURSE : JAVASCRIPT PROGRAMMING

FULL COURSE DETAILS

This training course aims to teach the reader the fundamentals of JavaScript. This course covers topics such as - variables and operators, control statements, functions, objects, frames, forms, dates, math and an introduction to cross-browser compatibility.

TO ACCESS THE FULL COURSE AND HUNDREDS OF OTHERS, CLICK HERE.


JavaScript has different types of operator, which can be classified by several criteria, such as:

  • Number of operands.
  • Type of operation.

Number of Operands

In general, there are three types of operators. Most JavaScript operators are binary ones that combine two expressions into a single, more complex expression. A binary operator requires two operands, one before the operator and one after the operator. For example, 13+14 or x*y.

JavaScript also supports a number of unary operators, which convert a single expression into a single more complex expression. A unary operator requires a single operand, either before or after the operator. For example, i-- or ++y.

Finally, JavaScript supports one ternary operator, ?:, which combines the value of three expressions into a single one. A ternary operator requires three operands. For example, (car.color == red) ? result += "got red car" : result += "got car with undefined color.";

Type of operations

There exist many types of operators, such as arithmetic, bitwise, comma, and string ones. They operate three types of operands, that is data types. Let us examine them in details.

Assignment Operators

An assignment operator assigns a value to its left operand based on the value of its right operand. The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x.

The other assignment operators are shorthand for standard operations, as shown in Table 2

Table 1. Assignment operators



Comparison Operators

A comparison operator compares its operands and returns a logical value based on whether the comparison is true or not. The operands can be numerical or string values. When used on string values, the comparisons are based on the standard lexicographical ordering. They are described in Table 3.

Table 2. Comparison operators

In these examples, assume var1 has been assigned the value 3 and var2 had been assigned the value 4.



Arithmetic Operators

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). These operators work as they do in other programming languages.

JavaScript provides the arithmetic operators listed in Table 4.

Table 3. Arithmetic Operators



NEXT PAGE



5 RELATED COURSES AVAILABLE
JAVASCRIPT PROGRAMMING
This training course aims to teach the reader the fundamentals of JavaScript. This course covers topics such as -....
HTML 4.0 INTRODUCTION
To create, format and publish a small website using HTML 4.0. You will learn to create web pages incorporating fo....
INTRODUCTION TO JAVA PROGRAMMING
The aims of this Java training courses is to understand the role that Java plays on the Internet; describe the be....
MICROSOFT VISUAL BASIC V6 INTRODUCTION
To go from the fundamentals of Visual Basic programming to the threshold of Advanced level. Gaining in depth prog....
MICROSOFT VISUAL BASIC 5.0 CLIENT SERVER DEVELOPMENT
This course teaches the skills required to develop client server applications using MS Visual Basic 5.0 Enterpris....
 
0 RELATED JOBS AVAILABLE
CONTACT US
Friday 19th March 2010  © COPYRIGHT 2010 - VISUALSOFT