分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

js判断数据类型

发布时间:2023-09-06 02:07责任编辑:沈小雨关键词:js数据类型

判断js中的数据类型有一下几种方法:typeof、instanceof、 constructor、 prototype、 $.type()/jquery.type(),接下来主要比较一下这几种方法的异同。

 

例子:

var a = "iamstring.";
var b = 222;
var c= [1,2,3];
var d = new Date();
var e = function(){alert(111);};
var f = function(){this.name="22";};
 
结果:


alert(typeof a) ?------------> string
alert(typeof b) ?------------> number
alert(typeof c) ?------------> object
alert(typeof d) ?------------> object
alert(typeof e) ?------------> function
alert(typeof f) ?------------> function

 
下表总结了typeof可能的返回值
类型结果
Undefined"undefined"
Null"object"(见下文)
Boolean"boolean"
Number"number"
String"string"
Symbol (ECMAScript 6 新增)"symbol"
宿主对象(由JS环境提供)Implementation-dependent
函数对象([[Call]] 在ECMA-262条款中实现了)"function"
任何其他对象"object"

js判断数据类型

原文地址:https://www.cnblogs.com/Marinnn/p/9395017.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved