JavaScript -基础- 函数与对象(二)

一、typeof与判断对象类型instanceof

1、typeof

typeof只能判断基础数据类型,无法判断引用数据类型

<script>

    var s="hello"

    var i=8; 

    alert(typeof(s))                       //输出string

    alert(typeof(i))                        //输出number

    var s2=new String("hello2")

    alert(typeof(s2))                     //输出为object,但是不知是那种object

</script>

2、instanceof

instanceof

猜你喜欢

转载自www.cnblogs.com/xibuhaohao/p/10455532.html