if-else用法

CreateTime--2016年10月31日14:22:25
Author:Marydon
if-else的多种用法:

//方式一
function test1 (t) {
  var bl = t || "测试1";
  console.log(bl);
}
test1();
//方式二
function test2 (t) {
  var bl;
  if (!t) {
    bl = "测试2";
  } else {
    bl = t;
  }
  console.log(bl);
}
test2();
//方式三
function test3 (t) {
  var bl = t ? t : "测试3";
  console.log(bl);    
}
test3();
//方式四
function test4 (t) {
  var bl;
  if (t) bl = t; else bl = "测试4";
  console.log(bl);
}
test4();
原文地址:https://www.cnblogs.com/Marydon20170307/p/6592860.html