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();

 

 

posted @ 2017-03-21 09:43  Marydon  阅读(295)  评论(0编辑  收藏  举报