Home > Web Front-end > JS Tutorial > Also use variable type forced conversion in JavaScript

Also use variable type forced conversion in JavaScript

高洛峰
Release: 2016-11-28 13:10:35
Original
977 people have browsed it

<script language="javascript">    var str = &#39;100&#39;;
    var num = Number(100);
    alert(typeof(num) + &#39;: &#39; + num);
    var obj = Object(str);
    alert(typeof(obj) + &#39;: &#39; + obj);
    var bool = Boolean(str);
    alert(typeof(bool) + &#39;: &#39; + bool);
 
    var num = 100;
    var str = String(num);
    alert(typeof(str) + &#39;: &#39; + str);
    var bool = Boolean(num);
    alert(typeof(bool) + &#39;: &#39; + bool);
    var obj = Object(num);
    alert(typeof(obj) + &#39;: &#39; + obj);
 
    var bool = true;
    var str = String(bool);
    alert(typeof(str) + &#39;: &#39; + str);
    var num = Number(bool);
    alert(typeof(num) + &#39;: &#39; + num);
    var obj = Object(bool);
    alert(typeof(obj) + &#39;: &#39; + obj);
 
    var obj = {};
    var str = String(obj);
    alert(typeof(str) + &#39;: &#39; + str);
    var num = Number(obj);
    alert(typeof(num) + &#39;: &#39; + num);
    var bool = Boolean(obj);
    alert(typeof(bool) + &#39;: &#39; + bool);
    </script>
Copy after login


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