当前位置:网站首页>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("执行此逻辑")
}
边栏推荐
- Analysis of graphical level-1 programming problem of Electronic Society: cat and mouse
- 医学影像分割的网站
- If no code is moved, the project access speed drops significantly the next day. Case analysis
- 力扣每日一题-第25天-495.提莫攻击
- C. Set or Decrease-Educational Codeforces Round 120 (Rated for Div. 2)
- FPGA 常用缩写及单词在工程领域内的意义
- 139. Séparation des mots
- JS traversal array (using the foreach () method)
- CAS操作在ARM和x86下的不同实现
- 【无标题】激光焊接在医疗中的应用
猜你喜欢

golang 重要知识:context 详解

Matlab| sparse auxiliary signal denoising and pattern recognition in time series data

JSON——学习笔记(消息转换器等)

Embedded software architecture design - program layering

自监督学习(SSL)Self-Supervised Learning

get_edges

【无标题】激光焊接在医疗中的应用

Important knowledge of golang: sync Once explanation

513. Find Bottom Left Tree Value

Important knowledge of golang: atomic atomic operation
随机推荐
Thymeleaf——学习笔记
SQL窗口函数怎么使用
子级文件拖到上一级
golang 重要知识:waitgroup 解析
Big factory Architect: how to draw a grand business map?
Web篇_01 了解web開發
Important knowledge of golang: detailed explanation of context
Wechat applet guides users to add applet animation page
图片保存:torchvision.utils.save_image(img, imgPath)
golang 重要知识:atomic 原子操作
TCP协议笔记
C. Set or Decrease-Educational Codeforces Round 120 (Rated for Div. 2)
C. Add One--Divide by Zero 2021 and Codeforces Round #714 (Div. 2)
ABP framework - data access infrastructure (Part 2)
MATLAB中iscellstr函数的使用
If no code is moved, the project access speed drops significantly the next day. Case analysis
513. Find Bottom Left Tree Value
批量注册组件
golang 重要知识:mutex
JS create an array (literal)