当前位置:网站首页>【无标题】js中的类型判断
【无标题】js中的类型判断
2022-04-23 05:54:00 【迷失的骆驼】
index.js
/** js的数据类型有: string, number, boolean, undefined, null, symbel object, array, function */
console.log('-----------Undefined--------')
console.log(undefined == undefined) // true
console.log(undefined === undefined) // true
console.log()
console.log('-----------Null--------')
console.log(null == null) // true
console.log(null === null) // true
console.log()
console.log('-----------String--------')
console.log('name' == 'name') // true
console.log('name' === 'name') // true
console.log()
console.log('-----------Number--------')
console.log(10 == '10') // true
console.log(10 == '010') // true
console.log(10 === '10') // false
console.log(10 === 10) // true
console.log(NaN == NaN) // false
console.log(NaN === NaN) // false
console.log(isNaN(NaN)) // true
console.log()
console.log('-----------Boolean--------')
console.log(true == true) // true
console.log(true === true) // true
console.log('-----------Object--------')
console.log({
} == {
}) // false
console.log({
} === {
}) // false
console.log(typeof {
}) // 'object'
console.log(typeof {
} == 'object') // true
// console.log(Object.isObject({})) // true
console.log('-----------typeof的值(无法判断 object, array, null--------')
console.log(typeof '') // 'string'
console.log(typeof 0) // 'number' -------- 111
console.log(typeof true) // 'boolean'
console.log(typeof undefined) // 'undefined'
console.log(typeof null) // 'object' -------- 222
console.log(typeof NaN) // 'number' -------- 111
console.log(typeof {
}) // object --------222
console.log(typeof []) // object --------222
console.log(typeof function () {
}) // function
console.log('-----------Object.prototype.toString.call的值--------')
console.log(Object.prototype.toString.call('')) // '[object String]'
console.log(Object.prototype.toString.call(0)) // '[object Number]'
console.log(Object.prototype.toString.call(true)) // '[object Boolean]'
console.log(Object.prototype.toString.call(undefined)) // '[object Undefined]'
console.log(Object.prototype.toString.call(null)) // '[object Null]'
console.log(Object.prototype.toString.call(NaN)) // '[object Number]'
console.log(Object.prototype.toString.call({
})) // '[object Object]'
console.log(Object.prototype.toString.call([])) // '[object Array]'
console.log(Object.prototype.toString.call(new Function ())) // '[object Function]'
console.log(Object.prototype.toString.call(function (){
})) // '[object Function]'
console.log('-----------if 条件判断--------')
if (0) {
// 非空判断
console.log(' if (0) ==> true ')
} else {
console.log(' if (0) ==> false ') // false
}
if ('0') {
console.log(' if ("0") ==> true ') // true
} else {
console.log(' if ("0") ==> false ')
}
if (undefined) {
console.log(' if (undefined) ==> true ')
} else {
console.log(' if (undefined) ==> false ') // false
}
if (null) {
console.log(' if (null) ==> true ')
} else {
console.log(' if (null) ==> false ') // false
}
if ({
}) {
console.log(' if ({}) ==> true ') // true
} else {
console.log(' if ({}) ==> false ')
}
if ([]) {
console.log(' if ([]) ==> true ') // true
} else {
console.log(' if ([]) ==> false ')
}
if (new Function()) {
console.log(' if (new Function()) ==> true ') // true
} else {
console.log(' if (new Function()) ==> false ')
}
/** -----------if 条件判断-------- if (0) ==> false if ("0") ==> true if (undefined) ==> false if (null) ==> false if ({}) ==> true if ([]) ==> true if (new Function()) ==> true */
版权声明
本文为[迷失的骆驼]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xufang461010923/article/details/124351210
边栏推荐
- 软件工程中的十三种文档
- Notes on advanced points of C language 4
- Qt 给应用程序加图标
- 修改注册表的值
- 金额输入框,用于充值提现
- cartographer_node 编译没问题,但是运行直接挂掉的bug
- Notes on advanced points of C language 2
- [UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit
- Shell脚本 单引号、双引号和反引号的区别
- cv_bridge 与opencv 版本不匹配的解决
猜你喜欢
随机推荐
监听除某元素之外点击事件
JS中的this指向
查漏补缺(三)
记第一次使用阿里字体图标库
Special register C51 / C52
微信小程序之 js 时间戳/1000 转换 秒,六个小时后,一天后,本周五 选项计算时间
C语言中volatile的使用
欢迎使用Markdown编辑器
FOC SVPWM函数PWMC_SetPhaseVoltage解析
Assembler 32-bit unsigned addition calculator
获取当前一周的时间范围
20220222回归职场
VHDL-任意分频器(50%占空比)
cv_bridge 与opencv 版本不匹配的解决
ROS包nmea_navsat_driver读取GPS、北斗定位信息笔记
Log writing method (with time)
cartographer_node 编译没问题,但是运行直接挂掉的bug
软件工程中的十三种文档
在MFC中使用printf
颜色字符串转换









