zoukankan      html  css  js  c++  java
  • typeof的用法和注意点

    	
    1==》js有六种基本数据类型。 String   Boolean Number null  underfined  Symbol
    但是《你不知道的javascript》的作者认为有7中。那一种是【对象】
    我觉得就是这6种。
    
    2==》查看变量的基本数据类型 使用typeof  但是如果是引用数据类型的话  使用instanceOf去查看
    因为typeof去检查函数和对象是可以的的。
    但是去检查数组,就会出错哈。
    
    
    3==》
    	var a;
    	console.log(typeof a);//undefined
    	// 如果一个变量定义了,但是没声明,它的类型和值就是underfined
    
    	var b = "heeh";
    	console.log(typeof b);//string
    
    	var c = null;
    	console.log(typeof c); //object
    	// 它的结果是object,这是设计上的缺陷哈。这是一个bug
    
    
    	function getSay() {
    	console.log("我是函数");
    	}
    	console.log(typeof getSay);//function
    
    	var obj = {
    		a: 1212
    	}
    	console.log(typeof obj); //object
    
    
    	var arr = [12, 34, 56];
    	console.log(typeof arr);//object
    	//有没有感觉奇怪。数组竟然也是Object。为啥函数不是Object呢???
            因为typeof检查时并不严谨,遇见数组,就会出现这一种情况哈。
    
  • 相关阅读:
    MVC1
    Linux中的软连接与硬连接
    python之multiprocessing(二):multiprocessing.Pool
    python之multiprocessing(一)
    python之paramiko(一)
    python_Exception之:TypeError: 'int' object is not iterable
    python之socket(一)
    python之pymysql(一)
    生成树协议--STP
    路由协议--RIP
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/12628795.html
Copyright © 2011-2022 走看看