Javascript中数据类型及其判别方法(typeof instanceof Object.prototype.toSting.call(obj)的区别)

今天总结了一下js中常见的数据类型及其判断方法如下,有错误欢迎指正:


以及一些实验性的例子如下:

function ha(){
		var str="1234";
	}
	var ha3 = ha;
	var ha4 = function(){};
	document.write(typeof(ha));//function
	document.write(typeof ha3);//function
	document.write(typeof ha4);//function
	document.write(typeof ha12);//undefined
	document.write(typeof ha());//undefined
	document.write(typeof NaN);//Number
	document.write(typeof NaN==NaN);//false
	document.write(ha() == undefined);//true
	document.write(0 == true);//false
	var num=86;
	var num2 = num;
	document.write(typeof num2); number
	function Book(_name,_money){
		this._name = _name;
		this._money = _money;
	}
	var book = new Book("hah",30);
	document.write(book instanceof Book);//true
	var para = new String("123");
	var type = Object.prototype.toString.call(book);//[Object Object]
	//var type = Object.prototype.toString.call(para);//[Object String]
	document.write(type);
	var test = Object.create(null);
	document.write(test instanceof Object);//false
	document.write(typeof test);//object


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值