Java Reference
In-Depth Information
statement
result
number
typeof 1
string
typeof "hello"
boolean
typeof true
typeof [] (or any array)
object
typeof {} (or any object)
object
"undefined")
typeof undefined
object
typeof null
trY it out Using Feature Detection
In this example, you modify ch8_example1.html and ensure that the page works in browsers that do
not support geolocation.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 8, Example 4</title>
</head>
<body>
<script>
function geoSuccess(position) {
var coords = position.coords;
var latitude = coords.latitude;
var longitude = coords.longitude;
var message = "You're at " + latitude + ", " + longitude
alert(message);
}
function geoError(errorObj) {
alert(errorObj.message);
}
if (typeof navigator.geolocation != "undefined") {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
} else {
alert("This page uses geolocation, and your " +
"browser doesn't support it.");
}
</script>
</body>
</html>
Save this example as ch8_example4.html .
Search WWH ::




Custom Search