Convert 'twenty' 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
"twenty" NaN"twenty" true

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Converting a text string to other types:</p>

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

<script>
var x = "twenty";
document.getElementById("demo").innerHTML =
"Number : " + Number(x) + "<br>" +
"String : " + String(x) + "<br>" +
"Boolean: " + Boolean(x);
</script>//w  ww  . j a  va  2  s .c  om

</body>
</html>

Related Tutorials