如何判断数据类型?
发布日期:2021-05-13 21:12:28 浏览次数:13 分类:精选文章

本文共 1974 字,大约阅读时间需要 6 分钟。

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

1. ���������������������������������

���������������������������������������typeof������������������������������������������������������������������������������������������

���������������

var a = "oiamstring.";
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������������������������������������������������

alert(typeof a == "string"); // true
alert(typeof a == String); // false

typeof������������������������������������������������������������������������������������������������������������������������������������������������������������instanceof������������

2. ������������������������������

������������������������������������instanceof���������������������������������������������������������������������������������������������������������������������������

���������������

var c = [1, 2, 3];
var d = new Date();
var f = function(){this.name="22";};

���������������

alert(c instanceof Array); // true
alert(d instanceof Date); // true
alert(f instanceof Function); // true
alert(f instanceof function); // false

���������������

  • ������instanceof������������������������
  • ���������������������������������������������������
  • ������������������������������������������

������

���������������������������������typeof���instanceof������������������������typeof������������������������������������instanceof������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:微信小程序placeholder设置自定义样式
下一篇:C#从txt文件读取数据

发表评论

最新留言

很好
[***.229.124.182]2025年04月16日 18时15分33秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章