当前位置:网站首页>Example of if directly judging data type in JS
Example of if directly judging data type in JS
2022-06-23 15:59:00 【Douqu programming】
if() It is generally used to judge the Boolean value of the calculation result , Such as ===,==,>,>=,<,<= etc. ; Or judge Function return value after forced conversion to Boolean value, etc ;
Automatically execute when judging Boolean() Method , Trying to convert the result to a Boolean value
But sometimes, when judging the data type directly , The following situations are Boolean() Results of transformation
1. Judged as false (false)
//var flag=undefined;
//var flag=null;
//var flag=0;
//var flag=NaN;
//var flag="";
//var flag;
//var flag=false;
if(!flag){
alert(" Execute this logic ")
}2. A situation judged to be true (true)
//var flag={}; // An empty object
//var flag=[];
//var flag=1; // except 0 and NaN All numbers except
//var flag=true;
//var flag=function(){};
//var flag=" "; // A string with only spaces
//var flag=/ /; // Regular expressions
if(flag){
alert(" Execute this logic ")
}
边栏推荐
猜你喜欢

Important knowledge of golang: detailed explanation of context

mysql事务与锁

golang 重要知识:waitgroup 解析

stylegan1: a style-based henerator architecture for gemerative adversarial networks

window远程桌面连接互传文件加速小技巧

SQL窗口函数怎么使用

MQ消息中间件理论详解
![生成二叉搜索平衡树[利用树递归特性]](/img/b3/f8edf45bdfdced7c3698088dbf7d84.png)
生成二叉搜索平衡树[利用树递归特性]

matlab: 如何从一些数据里知道是由哪些数据相加得出一个已知数
Sorting out and summarizing the handling schemes for the three major exceptions of redis cache
随机推荐
Important knowledge of golang: sync Once explanation
MySQL transactions and locks
一文看懂经典BUCK-BOOST负电压电路
Half wave loss equal thickness and equal inclination interference
FPN特征金字塔网络
Charge pump principle handout, how is the voltage "pumped"?
Web篇_01 了解web开发
进阶开发阶段-势若悬丝的加粗开始. 现在的一小步,明年的一大步
《利用CAS实现自旋锁》
企业想上MES系统?还得满足这些条件
C. Set or Decrease-Educational Codeforces Round 120 (Rated for Div. 2)
A transformer can only convert alternating current. How can I convert direct current?
MES在流程和离散制造企业的15个差别(上)
spdlog记录日志示例 - 使用sink创建logger
MIPI C-PHY协议你了解吗?手机高速接口之一
The meaning of FPGA abbreviations and words in engineering field
Sleuth + Zipkin
Sorting out and summarizing the handling schemes for the three major exceptions of redis cache
批量注册组件
Important knowledge of golang: waitgroup parsing