各种数据类型是否可进入if判断

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>
<script>
    if (NaN) {
        alert("NaN进入了")
    } //NaN 不会进入
    if (null) {
        alert("null进入了")
    } //null 不会进入
    if ("null") {
        alert("字符null会进入")
    } //字符null会进入
    if (0) {
        alert("0会进入")
    } //0不会进入
    if (undefined) {
        alert("undefined会进入")
    } //undefined 不会进入
    if ("") {
        alert("空会进入")
    } //空不会进入
    if (123) {
        alert("数字会进入")
    } //数字会进入
    if (xx) {
        alert("没定义的变量会进入");
    } //会报错,xx is not defined
</script>

</html>

 

posted @ 2017-09-29 10:20  莫笑我胡为  阅读(587)  评论(0编辑  收藏  举报