Home > Web Front-end > JS Tutorial > body text

Some minor issues about type conversion in js

php中世界最好的语言
Release: 2018-03-16 15:13:38
Original
1447 people have browsed it

This time I will bring you some minor questions about type conversion in js. What are the precautions about type conversion in js? The following are Let’s take a look at practical cases.

var str = false + 1;
var demo = false == 1;
if(typeof(a)&&-true + (+undefined) + ''){  console.log("我能输出吗?");
}
if(11 + '11' * 2 == 33) {  console.log("我能输出吗?");
}
!!' ' + !!'' - !!false||document.console.log("我能输出吗?");;
Copy after login

The following is the answer analysis

var str = false + 1;       //1
var demo = false == 1;       //false 
if(typeof(a)&&-true + (+undefined) + ''){  console.log("我能输出吗?");
}//输出  我能输出吗?//typeof(a) ==> typeof(undefined)  ==> "undefined"//"undefined"&&-true ==> -true ==> -1//+undefined ==> NaN//+"",结果是 "NaN"//转换成Boolean值为true
if(11 + '11' * 2 == 33) {  console.log("我能输出吗?");
}//11 + '11' * 2 == 33  ==>  11 + 22 == 33 ==>   11 + false ==> 11//输出  我能输出吗?
!!' ' + !!'' - !!false || document.console.log("我能输出吗?");
//没有输出  我能输出吗?
//!!把后面的变成Boolean值,!!' ' + !!''  ==>  true + false //true + false + false  ==> 1
//||符号前面为true就不往后走了
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese websiteOther related articles!

Recommended reading:

Nodejs uses Mongoose to create models and APIs

JavaScript's var and this, { }With function

Nodejs form verification and image upload


The above is the detailed content of Some minor issues about type conversion in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!