Saturday, April 21, 2012

Data type of Javascript: string and number

This exercise, the function typeof() is used to test the data type of various string and number object.


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile-Web-App: Javascript Exercise - data type</title>
<script>

function test(){
info = "<p>typeof \"\": " + typeof("") + "</p>"
 + "<p>typeof 'a': " + typeof('a') + "</p>"
 + "<p>typeof \"a\": " + typeof("a") + "</p>"
 + "<p>typeof 'abc': " + typeof('abc') + "</p>"
 + "<p>typeof \"abc\": " + typeof("abc") + "</p>"
 + "<p>typeof 0: " + typeof(0) + "</p>"
 + "<p>typeof 1: " + typeof(1) + "</p>"
 + "<p>typeof 1.0: " + typeof(1.0) + "</p>"
 + "<p>typeof 1.5: " + typeof(1.5) + "</p>"
 + "<p>typeof null: " + typeof(null) + "</p>";

document.getElementById("prompt").innerHTML=info;
}

</script>
</head>
<body onload="test();">
<h1>Mobile-Web-App: Javascript Exercise - data type</h1>
<div id="prompt"></div>
</body>
</html>


No comments:

Post a Comment