当前位置:网站首页>Judgment of single exclamation point and double exclamation point in JS

Judgment of single exclamation point and double exclamation point in JS

2022-06-13 08:47:00 fengyehongWorld

if (!null) {
    
    console.log('null Judgment is executed ');  // null Judgment is executed 
}
if (!undefined) {
    
    console.log('undefined Judgment is executed ');  // undefined Judgment is executed 
}
if (!'') {
    
    console.log(' Empty string judgment is performed ');  //  Empty string judgment is performed 
}
if (!' ') {
    
    console.log(' The space string judgment is performed ');
}
if (!0) {
    
    console.log('0 Judgment is executed ');  // 0 Judgment is executed 
}
console.log('---------------- Split line ----------------');

if (!!null) {
    
    console.log(' I will not be executed , I am a null');
}
if (!!undefined) {
    
    console.log(' I will not be executed , I am a undefined');
}
if (!!'') {
    
    console.log(' I will not be executed , I am an empty string ');
}
if (!!' ') {
    
    console.log(' I will be executed , I am a space string ');  //  I will be executed , I am a space string 
}
if (!!0) {
    
    console.log(' I will not be executed , I am a 0');
}
console.log('---------------- Split line ----------------');

//  When determining whether an object is an empty object , You can use it directly ! How to judge 
const obj = null;
if (obj === null || obj === undefined || obj === '') {
    
    console.log(' I am empty , Judge by troublesome means ');
}
if (!obj) {
    
    console.log(' I am empty , Judge in a simple way ');
}
原网站

版权声明
本文为[fengyehongWorld]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270537517516.html