(?:) is a ternary operator
(?:) is similar to if and can be used as a shortcut for if...else statements
condition? result 1: result 2; here you write the condition in front of a question mark (?) followed by result 1 and result 2 separated by a colon (:). Result 1 if the condition is met otherwise result 2
var b='gf'; (b == 'gf') ? a="true" : a="false"; console.log(a); output ----------------------------- true
var b=true; (b == false) ? a="true" : a="false"; console.log(a); output ----------------------------- false
typeof
typeof can be used to detect the data type of a given variable, possible return values: 1. 'undefined' --- this value is undefined;
2. 'boolean' --- the value is a boolean;
3. 'string' --- the value is a string;
4. 'number' --- this value is a numerical value;
5. 'object' --- the value is an object or null;
6. 'function' --- This value is a function.
var aa = 'my name is gaofan'; console.log(typeof aa); console.log(typeof 6); output // string // number
delete
delete is a unary operator that deletes object properties or array elements
var num = {x :1,y:2,k:3}; delete num.x; console.log(JSON.stringify(num)) 输出{"y":2,"k":3}
var num = [1,2,3]; delete num[2]; // delete the last element of the array console.log(JSON.stringify(num)) output [1,2,null]
Delete the array, the length of the array has changed, the length of the array is still 3
viod() is a unary operator, the operand can be any data type, and the result of the calculation is ignored and returns undefined
<a href="javascript:void window.open();">Open a new window</a>
eval() has only one parameter. If the parameter passed in is not a string, he returns this parameter directly. If the parameter is a string, he will compile the string as js code.
function a(){ eval("var x=1"); console.log(x); } a(); console.log(x); /* The first console.log() function can pop up 1 and the second will report an error because x is not defined The eval() function does not create a new scope, and its scope is the scope it is in */
Global eval() can declare or change variables
var globalEval = eval; //Define the global eval function alias var a = 'global' //global variable function c(){ var a = 'jimi,'; //local variable eval('a+="gaofan"'); //Directly change the value of local variables return a; //return the changed local variable } console.log(c()); //localchanged