| HTML | CSS | JavaScript |XHTML, XML, ASP, |
JS BasicsJS HomeIntroduction Basics Operators Functions Conditional Looping JS ReferencesString ObjectArray Object Date Object Math Object Window Object Frame Object Form Object Browser Object |
JavaScript OperatorsIn order to input, evaluate, manipulate, or display data, you need operators.
Operators are symbols and identifiers that represent the way that the data is changed or the way a combination of expressions is evaluated.
JavaScript supports both binary and unary operators.
Binary operators are operators two operands, x+y, while unary take only one operand, x++.
Operands are the variables which the operators refer to.
Assignment operatorsCombination of assignment and arithmetic Operators
x += y is short for x = x + y
x -= y is short for x = x - y
x *= y is short for x = x * y
x /= y is short for x = x / y
x %= y is short for x = x % y
Combinations of Assignment and Bitwise Operators
x <<= y is short for x = x << y
x >>= y is short for x = x >> y
x >>>= y is short for x = x >>> y
x &= y is short for x = x & y
x ^= y is short for x = x ^ y
x |= y is short for x = x | y
Arithmetic OperatorsArithmetic operators
+ addition
- subtraction
* multiplication
/ division
x++ short for x = x + 1
x-- short for x = x - 1
(you can use the ++, and -- operators as either prefixes or suffixes, ++x is same as x++)
Comparison OperatorsComparison Operators are used for comparing. The answer can be either true or false. Comparison Operators
String Operators+ operator is used to concantate strings, eg; if i have 2 strings "atgc" and "ttcg" and I put it into the document.write() method then document.write("atgc" + "ttcg") would display on the page "atgcttcg" Conditional OperatorsJavaScript uses two conditional operators, ? and :, to form conditional expressions. it is similar to the if statement. Conditional expressions return one of two values depending on the logical value of another expression. consider the following:
var aNumber = 98
var resultMsg = (aNumber == 89) ? "Same number" : "Different number";
alert(resultMsg);
The above would return and alert Different number The reason because aNumber contains the value 98 however the test statement makes it return true if aNumber == 89, the statement left of : is displayed if the test condition is true, while the statemetn right of : is displayed when the test condition is false. Boolean OperatorsBoolean operators (logical operators) are used in conjuction with expressions that return logical values. Boolean Operators
The typeof OperatorThe typeof operator returns the type of data that its operand currently holds. typeof unescape returns the string "function". |