Home > Web Front-end > JS Tutorial > What is the function of !!() in js? Detailed explanation of the role of !!() in js

What is the function of !!() in js? Detailed explanation of the role of !!() in js

云罗郡主
Release: 2018-10-22 14:57:30
forward
4525 people have browsed it

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.

What is the function of !!() in js? Detailed explanation of the role of !!() in js

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();
Copy after login

Implicit conversion:

var a = '111'+0;//a的结果为数值型;
var b = 111+'';//b的结果为字符串类型;
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template