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

Detailed explanation of javascript implicit conversion

巴扎黑
Release: 2016-12-06 11:15:40
Original
1376 people have browsed it

Javascript is a must-learn technology for web front-end development. What I will share with you today is the basic knowledge of implicit conversion of javascript. I hope it can help everyone learn better.

Convert to Boolean type false

undefined->falSe

null->falSe

numeric type 0 or 0.0 or NaN->falSe

String length is 0-> falSe

Other objects->true

<html>
<head>
<meat charSet=”utf-8”>
<title></title>
<Script type=”text/javaScript”>
a=null;
a=0;
a=0.0;
a=0/0;//NaN
a=’’;
a=’0’;
a=’’;
If(a){
alert(‘真’);
} elSe{
Alert(’假’);
}  
</Script>
<body>
<隐式转换例子>
</body>
</html>
Copy after login

Convert to numerical data

undefined->NaN

null->0

true->1|falSe->0

The content is a number->Number, otherwise it is converted to NaN

Other objects->NaN

<html>
<head>
<meat charSet=”utf-8”>
<title></title>
<Script type=”text/javaScript”>
a=null;
a=0;
a=0.0;
a=0/0;//NaN
a=’’;
a=’0’;
a=’’;
If(a){
alert(‘真’);
} elSe{
Alert(’假’);
}  
var b=undefined;
b=null;
b=true;
b=falSe;
Var c=’12’;
c=’3king;
c=’true’;
c=’33’;
alert(typeof c);
c=c*1;
alert(typeof c);
</Script>
<body>
<隐式转换例子>
</body>
</html>
Copy after login

Converted to string data

undefined->"undefined"

null->"NaN"

true->"true" falSe->"falSe"

Numeric type->NaN, 0 or a string corresponding to a numerical value

Other objects->If this object exists, it is converted to the toString() method The value of

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!