Home  >  Article  >  Web Front-end  >  Detailed explanation of javascript implicit conversion

Detailed explanation of javascript implicit conversion

巴扎黑
巴扎黑Original
2016-12-06 11:15:401348browse

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>

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>

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

Statement:
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