Home > Article > Web Front-end > What is the function of !!() in js? Detailed explanation of the role of !!() in js
The content of this article is about what is the function of !!() in js? The detailed explanation of the function of !!() in js has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
We know that JavaScript is a weakly typed language, but sometimes it needs to be forced to the corresponding type during use. so,! ! (), this writing method has the effect of converting weak types into strong types.
When it comes to type conversion, we have to mention two concepts: explicit conversion and implicit conversion.
Explicit conversion:
const a = parseInt(‘1111111111111’); const b = Obj.toString();
Implicit conversion:
var a = '111'+0;//a的结果为数值型; var b = 111+'';//b的结果为字符串类型;
Return to !!().
For example: a defaults to undefined! a is true! ! a is false, so the value of b is false, not undefined. Writing this way can facilitate subsequent judgment and use.
so,! ! The function of (a) is to cast a to boolean.
The above is what is the function of !!() in js? A detailed introduction to the role of !!() in js. If you want to know more about JavaScript video tutorial, please pay attention to the PHP Chinese website.
The above is the detailed content of What is the function of !!() in js? Detailed explanation of the role of !!() in js. For more information, please follow other related articles on the PHP Chinese website!