JavaScript DHTML/Data Type/typeof

Материал из Web эксперт
Перейти к: навигация, поиск

Output the type information

 
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
var x = "Hello", y;
alert("Variable x value is " + typeof(x));
alert("Variable y value is " + typeof(y));
alert("Variable z value is " + typeof(z));
</script>
</head>
<body>
</body>
</html>



Use typeof to check the type for different type variables

 

<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var num1 = 1;
var num2 = 1;
var num3 = 19;
var value = "84";
var name1 = "A";
var name2 = "BB";
alert(typeof num1);
alert(typeof num2);
alert(typeof num3);
alert(typeof value);
alert(typeof name1);
alert(typeof name2);
</script>
</body>
</html>