JavaScript技术总结1:类型检查小工具,看完不会的来打我

type.undefined = x => x === undefined;

// check for nil type. Either null or undefined

type.nil = x => type.null(x) || type.undefined(x);

// check for strings and string literal type. e.g: ‘s’, “s”, str, new String()

type.string = x => !type.nil(x) && (typeof x === ‘string’ || x instanceof String);

// check for number or number literal type. e.g: 12, 30.5, new Number()

type.number = x => !type.nil(x)

&& (// NaN & Infinity have typeof “number” and this excludes that

(!isNaN(x) && isFinite(x)

&& typeof x === ‘number’

) || x instanceof Number);

// check for boolean or boolean literal type. e.g: true, false, new Boolean()

type.boolean = x => !type.nil(x) && (typeof x === ‘boolean’ || x instanceof Boolean);

// check for array type

type.array = x => !type.nil(x) && Array.isArray(x);

// check for object or object literal type. e.g: {}, new Object(), Object.create(null)

type.object = x => ({}).toString.call(x) === ‘[object Object]’;

// check for provided type instance

type.type = (x, X) => !type.nil(x) && x instanceof X;

// check for set type

type.set = x => type.type(x, Set);

// check for map type

type.map = x => type.type(x, Map);

// check for date type

type.date = x => type.type(x, Date);

return type;

})();

[

最后

给大家分享一些关于HTML的面试题。


(img-wXglBLQf-1727200915196)]
[外链图片转存中…(img-LFJyPSLv-1727200915196)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值