Home arrow JavaScript arrow The Power of JavaScript: Operators

The Power of JavaScript: Operators

We have discussed the very basics of Javascript. Until now, we have not written much code. There's still much more to knowing and learning to master the basics of Javascript. In this article, we talk about how we can perform arithmetic operations, comparison operations and increment/decrement operations using Javascript operators.

Author Info:
By: Michael Youssef
Rating: 5 stars5 stars5 stars5 stars5 stars / 33
July 19, 2005
  1. · The Power of JavaScript: Operators
  2. · Arithmetic Operators
  3. · Comparison Operators
  4. · Increment and Decrement Operators

print this article

The Power of JavaScript: Operators
(Page 1 of 4 )

Before we talk about operators, we must define what an expression is. An expression is a code snippet that yields a value. For example, the snippet 5 + "Five" is called an expression because the Javascript interpreter is able to evaluate it and produce a value (which is the string value "5Five"). We use expressions to build Javascript statements. We have said that a statement is very similar to a sentence in the English language in which it tells the interpreter to do something.

In the expression 5 + "Five" we have not told the interpreter what to do yet with the value that it has produced, so we need to write a statement to the interpreter in order to execute it. The statement may look like this (for our example): var aString = 5 + "Five". Now the Interpreter understands that we need to concatenate the numerical value 5 with the string value "Five" and assign the resultant value to the variable aString.

As you can see, we have used the plus symbol (which we call it the addition operator in Javascript) to write a somewhat complex expression. In fact a value like "hi" or 3 is considered an expression because the interpreter considers any code snippet that produces a value to be an expression. It happens that "hi" is a code snippet that produces a string value of "hi". We use operators like the addition operator to build complex expressions, so let's take a look at operators.

An operator is a symbol with an associated known operation to the language. It works on one or more operands. Let's take the addition operator as an example. The + is a symbol, and the associated operation is adding two numerical values like 3 + 9; the numerical values are what we call the operator's operands. We can think of the operands as the values that the operator will work on, like 3 and 9.

The addition operator is called a binary operator because it works on two operands. There are two more categories of operations. The unary operator has only one operand, and the ternary operator has three Operands (we will talk about such operators too). Now let's meet the first family of operators that we will discuss.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials