2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

js if条件判定 早見表

Last updated at Posted at 2020-01-25
// 値
var v;
var v = '';
var v = 0;
var v = '0';
var v = null;
var v = 'null';
var v = undefined;
var v = 'undefined';
var v = [];

// console
console.log('v:' + v);

#条件が空文字

console if(v) if(v == '') if(v === '') if(!v) if(v != '') if(v !== '')
v value:undefined false false false true true true
v = '' value: false true true true false false
v = 0 value:0 false true false true false true
v = '0' value:0 true false false false true true
v = null value:null false false false true true true
v = 'null' value:null true false false false true true
v = undefined value:undefined false false false true true true
v = 'undefined' value:undefined true false false false true true
v = [] value: true true false false false true

#条件がnull

console if(v == null) if(v === null) if(v != null) if(v !== null)
v value:undefined true false false true
v = '' value: false false true true
v = 0 value:0 false false true true
v = '0' value:0 false false true true
v = null value:null true true false false
v = 'null' value:null false false true true
v = undefined value:undefined true false false true
v = 'undefined' value:undefined false false true true
v = [] value: false false true true

#条件がundefined

console if(v == undefined) if(v === undefined) if(v != undefined) if(v !== undefined)
v value:undefined true true false false
v = '' value: false false true true
v = 0 value:0 false false true true
v = '0' value:0 false false true true
v = null value:null true false false true
v = 'null' value:null false false true true
v = undefined value:undefined true true false false
v = 'undefined' value:undefined false false true true
v = [] value: false false true true
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?