JavaScript OR (||) variable assignment explanation

后端 未结 12 2393
北恋
北恋 2020-11-21 06:41

Given this snippet of JavaScript...

var a;
var b = null;
var c = undefined;
var d = 4;
var e = \'five\';

var f = a || b || c || d || e;

alert(f); // 4
         


        
12条回答
  •  [愿得一人]
    2020-11-21 06:54

    Return output first true value.

    If all are false return last false value.

    Example:-

      null || undefined || false || 0 || 'apple'  // Return apple
    

提交回复
热议问题