Return to Kroll Design home page

JavaScript Tutorials

« Return

typeof operator

To see what type of variable something is, use the typeof operator.


<script type="text/javascript">
var myLiteral = "Hello"; document.write("variable myLiteral has a value of \"", myLiteral, "\" and a type of ", typeof myLiteral, "<br><br>"); var myInteger = 333; document.write("variable myInteger has a value of ", myInteger, " and a type of ", typeof myInteger, "<br><br>"); var myDollarAmount = 238.54; document.write("variable myDollarAmount has a value of ", myDollarAmount, " and a type of ", typeof myDollarAmount, "<br><br>"); var myTrueFalseFlag = false; document.write("variable myTrueFalseFlag has a value of ", myTrueFalseFlag, " and a type of ", typeof myTrueFalseFlag, "<br><br>"); var myEmptyVoid = null; document.write("variable myEmptyVoid has a value of ", myEmptyVoid, " and a type of ", typeof myEmptyVoid, "<br><br>"); var myParseIntResult = parseInt("eleven"); document.write("variable myParseIntResult has a value of ", myParseIntResult, " and a type of ", typeof myParseIntResult, "<br>"); //]]> </script>


(see parseInt regarding the value NaN, which stands for "not a number")

« Return

©2012 Kroll Design    781.910.3694
Last modified: 12/31/1969 7:00 PM