当前位置:网站首页>js中 if 直接判断 数据类型 结果举例
js中 if 直接判断 数据类型 结果举例
2022-06-23 15:27:00 【豆趣编程】
if()一般用来判断计算结果的布尔值,如 ===,==,>,>=,<,<= 等;或者判断 强制转化成布尔值后的函数返回值等;
判断时自动执行 Boolean() 方法,试图将结果转化成布尔值
但有时候直接判断数据类型的时候,以下几种情况是Boolean()转化的结果
1.判断为假的情况(false)
//var flag=undefined;
//var flag=null;
//var flag=0;
//var flag=NaN;
//var flag="";
//var flag;
//var flag=false;
if(!flag){
alert("执行此逻辑")
}2.判断为真的情况 (true)
//var flag={}; //空对象
//var flag=[];
//var flag=1; //除了0和NaN外的所有数字
//var flag=true;
//var flag=function(){};
//var flag=" "; //只有空格的字符串
//var flag=/ /; //正则表达式
if(flag){
alert("执行此逻辑")
}
边栏推荐
- MySQL transactions and locks
- [普通物理] 光的衍射
- Web articles_ 01 understanding web development
- Important knowledge of golang: waitgroup parsing
- Android kotlin collaboration Async
- 苹果 iPhone、三星手机等电子产品开始经平行进口渠道进入俄罗斯
- 139. 单词拆分
- 139. word splitting
- This year's cultural entertainers have turned their sidelines into their main business
- Origin of sectigo (Comodo) Certificate
猜你喜欢
![[普通物理] 光的衍射](/img/1a/20dbd15e0c8c91a3e59753b2f6797a.png)
[普通物理] 光的衍射

Important knowledge of golang: atomic atomic operation

stylegan3:alias-free generative adversarial networks

513. Find Bottom Left Tree Value

Stone from another mountain - Intelligent Question and answer technology in wechat search

FPN特征金字塔网络

mysql事务与锁

Important knowledge of golang: mutex

get_edges

Jsr303 data verification
随机推荐
数组自带的方法
Different implementation of CAS operation under arm and x86
任何代码未动的情况下第二天项目访问速度明显下降,案例分析
Explore the "store" on the cloud. The cloud store is newly upgraded!
请问期货开户去哪个平台好?网上期货开户安全吗?
C. Phoenix and Towers-Codeforces Global Round 14
Explain in detail the principle and implementation of redis distributed lock
npm 如何发包 删包
stylegan1: a style-based henerator architecture for gemerative adversarial networks
F5 application strategy status report in 2022: edge deployment and load security become the focus of attention in the Asia Pacific Region
stylegan3:alias-free generative adversarial networks
要买的理财产品年限长,划算吗?
C. Add One--Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
电子学会图形化一级编程题解析:猫捉老鼠
电荷泵原理讲义,电压是怎么“泵”上去的?
pytorch:模型的保存与导出
The "shoulder" of sales and service in the heavy truck industry, Linyi Guangshun deep ploughing product life cycle service
Which platform is a good place to open a futures account? Is it safe to open an online futures account?
Horizon development board commissioning
看,这就是调制解调原理分析!附仿真文件