JavaScript Special Operators
| Special Operator | Description | Example |
| ?: (Conditional) | {condition)? iftrue : iffalse | y=-1 x=(y<0)? 5: 10 result; x=5 |
| , | You can use the comma operator when you want to include multiple expressions in a location that requires a single expression. | for (var i=0, j=9; i <= 9; i++, j--) |
| delete | The delete operator is used to delete an object | fruit = new Array ("apple", "pear", "orange",
"cherry", "grape"); delete fruit[2]; |
| new | The new operator can be used create an instance of a user-defined object type or of one of the built-in object types. | function author(name, real_name, age) { this.name = name this.real_name = real_name this.age = age } author1 = new author("John Lynch", "Charlie Schwarz", 43) |
| this | Keyword that you can use to refer to the current object. | function describeAge(obj) { if(obj.year < 1996) return "Old-fashioned" else return "Good-as-new" } function car(make, year, description) {this.make = make, this.year = year, this.description = describeAge(this)} myCar = new car("Ford", "1993", describeAge(this)) |
| typeof | The typeof operator returns the type of an unevaluated operand which can be a number, string, variable, object or keyword. | Var age = 33 typeof(age) returns number typeof 33 returns number |
| void | The void operator specifies an expression to be evaluated without returning a value. |
The following example creates a hyperlink on the word "green"
which, when clicked, changes the background color to light green: Code: Sam turned <a href= "javascript:void(document.bgColor='lightgreen') " > green </a>. |
0 comments:
Post a Comment