This article mainly introduces the double exclamation mark in JavaScript (!!) The role of the need for a friend can refer to the following
Often see such examples: code as follows: Var a; var b=!! a; A default is undefined.!a is true,!! A is false, so the value of B is false, not undefined, and not other values, primarily for subsequent judgment. !! Typically used to cast a subsequent expression to a Boolean type of data (Boolean), which is only true or false; because JavaScript is a weakly typed language (a variable has no fixed data type), it is sometimes necessary to cast to the appropriate type, like : Code as follows: A=parseint ("1234″) a=" 1234″-0//Convert to Digital b=1234+ ""//Convert to string c=someobject.tostring ( //Convert object to string where the 1th and 4th are explicit conversions, 2, 3 for implicit conversions Boolean conversions, JavaScript convention rules for false, undefinded, NULL, 0, "" is false true, 1, "somestring", [Object] for true null and undefined, and other implicitly converted values, with the! Operator will produce true results, So the effect of using two exclamation points is to convert these values to "equivalent" Boolean values; look at the: code as follows: Var foo; alert (!foo)//undifined case, An exclamation point returns true; alert (!goo);//null case, an exclamation point returns true; var o={flag:true}; var test=!! o.flag;//equivalent to Var test=o.flag| | false; alert (test); This example shows that when undifined and Null are returned with an exclamation point, the return is false with two exclamation marks, so the effect of the two exclamation points is that If the value of the variable is explicitly set (not null/undifined/0/""Equivalent", the result is returned based on the actual value of the variable, and if there is no setting, the result returns false.