javascript: operator
In fact, the operator if you have a computer language base should know, perhaps even more proficient than I am, so I do not explain more, to say a few other unfamiliar bar!
1. In operator: The in operator requires that the operand on the left is a string, or it can be converted to a string, and the right-hand operand is an array or an object that returns True if the value on the left is an attribute of the object on the right.
Copy Code code as follows:
var objvalue = {X:1,y:7};
document.write ("X is in ObjValue:" + ("x" in ObjValue) + "<br/>");
Output x is in Objvalue:true
2, the conditional operator (?:)
The operator is the only ternary operator in JavaScript (3 operands), and the first operand must be a Boolean value, and the second and third operands can be of any type. If the value of the operand is not true, the value is the value of the second operand, and the flase-is the third operation count.
Copy Code code as follows:
document.write (1>0?8:4)
The output 8,1 must be greater than 0, so return to the second shipment count.
3, typeof operator
typeof is a unary operator that is used to determine the type of operands, such as the number returned by the operand, and the string is returned. NOTE: For null it is returned as object type. This operator is more or less.
Copy Code code as follows:
document.write ("typeof number 8:" + typeof 8 + "<br/>");/output typeof number 8:number
document.write ("typeof string:" +typeof ("money") + "<br/>");/output typeof string Money:string
document.write ("typeof Boolean True:" +typeof (True) + "<br/>");/Output typeof Boolean True:boolean
document.write ("typeof Array:" +typeof ([]) + "<br/>");/output typeof Array:object
document.write ("typeof null:" +typeof (NULL) + "<br/>");/output typeof Null:object
document.write ("typeof Undefined:" +typeof (Undefined) + "<br/>");/output typeof undefined:undefined
4, delete operator
Delete is also a unary operator that deletes the property, array element, or variable of the object specified by the operand, returns true if the deletion succeeds, and returns False if the OP count cannot be deleted.
Copy Code code as follows:
var deleteobj = {one: "One", Two: "Two", Three: "Three"};
document.write ("Delete element is succeed:" + (delete deleteobj.one) + "<br/>");/output Delete element is Succeed:true
document.write ("Select one in Deleteobj:" + typeof (Deleteobj.one) + "<br/>");/output Select one in deleteobj:undefined
document.write ("Delete element is succeed:" + (delete deleteobj) + "<br/>");/output Delete element is Succeed:false
document.write ("Delete defined x:" + (delete x) + "<br/>");/output Delete defined X:true
var x = 1;
The above reflects the delete, can delete the object's properties, variables, cannot delete objects, undefined variables.
javascript: statement
1, If,else if statement
Because it is the basic statement, I do not introduce more, directly to a few examples, the following control statements will be used later.
Copy Code code as follows:
var expression;
if (!expression) document.write ("I declare, but not undefined value" + "<br/>"); Output: I declare, but no value is undefined
Because the value of the expression is undefined undefined, it is converted to false in the Boolean type.
if (!null) document.write ("I use Boolean also false" + "<br/>")/output: I use Boolean and False
var obj1 = {};
if (obj1) document.write ("Obj1 is not a null object" + "<br/>");/output obj1 is not a null object
if (!obj1.one) document.write ("Obj1.one is a null object" + "<br/>");//obj1.one is a null object
Similar to the above statements may be used frequently, to be able to understand. Can't be sloppy
2, switch statements, while, Do...while, for, for...in
The above statement and other languages are nothing special, directly on the last month I learned C # to do the topic, but this time we are using JavaScript.
Copy Code code as follows:
To perform sorting an array
function Comparenumber (OBJARR1)
{
if (!OBJARR1)
{
Throw ("parameter cannot be empty!");
Return
}
var finished = true;//used to control the while loop
Todo
{
Finished = false;
for (var i=0;i<objarr1.length;i++)//variable Array length property returns an array of lengths
{
if (objarr1[i]>objarr1[i+1])//comparison
{
var temp = objarr1[i];
Objarr1[i] = objarr1[i+1];
OBJARR1[I+1] = temp;
Finished = true;//continues looping until the above comparison condition is not met and the while does not loop.
}
}
}while (finished);
}
This function performs a print task
function Displayarray (arr)
{
For (Var val in arr)
{
document.write (Arr[val] + "T");//\t is a tab
}
}
var Numberarray = [34,45,2,3,54,65,123];//declares an array
Comparenumber (Numberarray);//Sort
Displayarray (Numberarray);//Output
Output: 2 3 34 45 54 65 123
3, with statement
With with, you can reduce a lot of input, and in JavaScript clients, deep nested objects can be used with, but it runs slowly.
Summary: In fact, there are many other statements, here I do not write more than repeated.