Previous Example-|-Next Example-|-Return to Chapter Listing

Example 5.17:
Using typeof


[This example works with Netscape Navigator 3. It will work in most cases with Internet Explorer 3, but typeof in that browser cannot correctly identify the item in all cases.]

The typeof operator will tell you what sort of string, variable, method, function, keyword, object, or property you have.


In the HEAD we have this script: <script language="JAVASCRIPT"> <!-- var sSize="big" var nSize=1 var todayDate=new Date() //--> </script> In the BODY of the page we have this script: <script language="JAVASCRIPT"> <!-- document.write("sSize = " + typeof sSize + "<BR>") document.write("nSize = " + typeof nSize + "<BR>") document.write("todayDate = " + typeof todayDate + "<BR>") document.write("nothingAtAll = " + typeof nothingAtAll + "<BR>") document.write("null = " + typeof null + "<BR>") document.write("false = " + typeof false + "<BR>") document.write("true = " + typeof true + "<BR>") document.write("666 = " + typeof 666 + "<BR>") document.write("A little bit of text = " + typeof 'A little bit of text' + "<BR>") document.write("document.linkColor = " + typeof document.linkColor + "<BR>") document.write("document.lastModified = " + typeof document.lastModified + "<BR>") document.write("document.anchors = " + typeof document.anchors + "<BR>") document.write("window.history = " + typeof window.history + "<BR>") document.write("window.length = " + typeof window.length + "<BR>") document.write("Math.E = " + typeof Math.E + "<BR>") document.write("blur = " + typeof blur + "<BR>") document.write("Date = " + typeof Date + "<BR>") document.write("String = " + typeof String + "<BR>") //--> </script>
Previous Example-|-Next Example-|-Return to Chapter Listing