The operators in JavaScript are similar to those in C/C ++, but there are several differences. Compared with C/C ++, several different operators are added, including in, instanceof, typeof, delete. you need to be familiar with it.
2.1 In Operator
The in operator requires that the number of operations on the left be a string or can be converted to a string. The number of operations on the right is an object or an array.
If the value on the left of the operator is an attribute name of the right object, true is returned.
1 VaR Point = {X:1, Y:1}
2 VaR Has_x_coord = "X" In Point; // True
3 VaR Has_y_coord = "Y" In Point; // True
4 VaR Has_z_coord = "Z" In Point; // False
5 VaR TS = "Tostring" In Point; // Inherited from the object property, true; 2.2 instanceof Operator
The instance operator requires that the Operation number on the left be an object and the operation number on the right be the name of the object class.
If the object on the left of the operator is an instance of the right class, true is returned; otherwise, false is returned.
1 VaR D = New Date ();
2 D Instanceof Date; // True
3 D Instanceof Object; // True
4 D Instanceof Number; // False
5 VaR A = [ 1 , 2 , 3 ];
6 A Instanceof Array; // True
7 A Instanceof Regexp; // False
2.3 typeof Operator
The typeof operator is a unary operator and the number of operations is of any type. Its return value is a string. the return value indicates the type of the number of operations.
If the number of operations is a number, string, or Boolean value, the returned result is "Number", "string", and "Boolean ". For objects, arrays, and null, it returns "object ".
For a function, the return value is "function". If the number of operations is not fixed, the return value is "undefined ".
2.4 Delete Operator
The delete operator is not used to delete objects. It is used to clear the object memory.
It is used to delete the attribute of the specified object by the operator, array element or variable.
Deleted successfully. True is returned.
1 VaR O = {X:1, Y:2}
2 Delete O. X; // Return true;
3 Delete O. Y; // Return true;
4 Delete O. X; // Delete A Nonexistent element (Deleted) and return true
5 Delete O; // Cannot be deleted, return false