javascript typeof 运算符

typeof运算符简介

在JavaScript中,typeof运算符用于返回它的操作数当前所容纳的数据的类型,这对于判断一个变量是否已被定义特别有用。

举例:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        document.write(typeof(1)+ "<br/>");
        document.write(typeof("javascript")+ "<br/>");
        document.write(typeof(null)+ "<br/>");
        document.write(typeof(undefined)+ "<br/>");
    </script>
</head>
<body>
</body>
</html>

在浏览器预览效果如下:

javascript typeof 运算符