The Delete Operator in JavaScript
The delete operator can delete a property of an object, array element or an undeclared variable.
var ob = { a:1, b:2 };
delete ob.b.
The delete operator can delete a property of an object, array element or an undeclared variable.
var ob = { a:1, b:2 };
delete ob.b.
The new Operator creates a new object and invokes a constructor function to initialize it.
i = new object;
The typeof Operator determines the datatype of the operand.
var name = "Keith"; document.write(typeof(name));
The conditional operator is the only JavaScript operator that takes three operands. The operator can have one of two values based on a condition. The syntax is:
condition ? val1 : val2
If condition is true, the operator has the value of val1. Otherwise it has the value of val2. You can use the conditional operator anywhere you would use a standard operator.
For example,
status = (age >= 18) ? “adult” : “minor”
The instanceof operator expects a left-side operand that is an object and a right-side operand that is the name of a class of objects.
var names = new String("Keith");
names instanceof String;
// returns true
var names2 = "Aoife";
names2 instanceof String;
// returns false (names2 is not a String object)
The In Operator expects a left-side that is or can be converted to a string. it expects a right-side operand that is an object or array. It evaluates to true if the left-side value is the name of a property of the right-side object.
var names = new Array("Keith", "Aoife", "Sasha");
delete trees[2]; // Delete index number 3
3 in name; // returns false
The != and !== operators test for the exact opposite of the == and === operators.
The Inequality Operator (!=)
The Inequality operator returns false if two values are equal to each other.
The NonIdentity Operator (!==)
The Nonidentity operator returns false if two values are idetical to each other.
The Equality Operator (==)
The equality operator (==) checks whether two operands are the same and returns true if they are the same and false if they are different.
The Identity Operator (===)
The identity operator checks whether two operands are “identical”.
These rules determine whether two values are identical:
Addition Operator (+)
The addition operator adds numbers together and also joins strings together.
document.write(2 + 2);
Subtraction Operator (-)
Subtracts two or more numbers .
document.write(5 - 3);
Multiplication Number (*)
Multiplies two or more numbers.
document.write(5 * 2);
Division Operator (/)
The Division Operator divides its first operand by its second. If an outputted result could be a floating point number (4.5), JavaScript will return a floating point number and not an integer.
document.write(9/2);
Modulo Operator (%)
The Modulo operator returns the remainder when the first operand is divided by the second operand.
document.write(9%2);
Unary Operator (-)
When the subtraction operator is used before an operand, it converts a positive value to a negative value.
var one = 1;
document.write(-one);
Unary Operator (+)
When the addition operator is used before an operand, it converts a negative value to a positive value.
var one = -1;
document.write(+one);
Increment Operator (++)
The Increment Operator increments, adds 1 to a variable value. If (++) is used before the operand, it increments and evaluates the operand to the incremented value. If used after the operand, it increments the operand but evaluates to the incremented value of that operand.
var ten = 10;
document.write(++ten);
Decrement Operator (–)
The Decrement Operator decrements, subtracts 1 to a variable value. If (–) is used before the operand, it decrements and evaluates the operand to the decremented value. If used after the operand, it decrements the operand but evaluates to the decremented value of that operand.
var ten = 10;
document.write(--ten);
An expression is a phrase of JavaScript that a JavaScript interpreter can evaluate to produce a value.