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

来源:互联网 发布:grid.base.js 编辑:程序博客网 时间:2024/04/30 08:33

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


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

function ha(){var str="1234";}var ha3 = ha;var ha4 = function(){};document.write(typeof(ha));//functiondocument.write(typeof ha3);//functiondocument.write(typeof ha4);//functiondocument.write(typeof ha12);//undefineddocument.write(typeof ha());//undefineddocument.write(typeof NaN);//Numberdocument.write(typeof NaN==NaN);//falsedocument.write(ha() == undefined);//truedocument.write(0 == true);//falsevar num=86;var num2 = num;document.write(typeof num2); numberfunction Book(_name,_money){this._name = _name;this._money = _money;}var book = new Book("hah",30);document.write(book instanceof Book);//truevar 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);//falsedocument.write(typeof test);//object


0 0