Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

var s = str || "default"; 
var l = len || s.length; 
var o = option || "i";
请问这么声明变量什么意思呢?谢谢。

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
488 views
Welcome To Ask or Share your Answers For Others

1 Answer

这是短路语法,它比条件语句更加清晰

    let str = a || b;

若 a 为 true,则 str = a

若 a 为 false,则 str = b

    let str = a && b;

若 a 为 true,则 str = b

若 a 为 false,则 str = a

理解

比如 a && b ,a 如果是 true,那么此时结果只跟 b 有关,相当于结果就是 b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...