判断数据类型

	function chekFn(a){
		var myas = typeof a;
		switch(myas){
			case 'undefined':
				console.log('undefined');
				break;
			case 'null':
				console.log(null);
				break;
			case 'number':
				console.log('num');
				break;
			case 'string':
				console.log('string');
				break;
			case 'boolean':
				console.log('boolean');
				break;
			case 'object':
				console.log('object')
				break;
		}
	}
	chekFn('dfas');  //string
	chekFn();  // undefined
	chekFn(true); //boolean
	chekFn(null); //object
	chekFn(undefined); //undefined
	chekFn([]); //object

  

posted @ 2018-06-19 10:19  adongP  阅读(131)  评论(0编辑  收藏  举报