Convert 0 to number, string and Boolean - Javascript Data Type

Javascript examples for Data Type:Data Type Cast

Introduction

OriginalValueConverted to Number Converted to String Converted to Boolean
00 "0"false

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Converting the number 0 to other types:</p>

<p id="demo" style="font-family:courier"></p>

<script>
var x = 0;/*from   w w w.  j  a v  a  2 s  . com*/
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>

</body>
</html>

Related Tutorials