javascript - A problem with JS multivariate operators
过去多啦不再A梦
过去多啦不再A梦 2017-07-05 11:08:37
0
2
1044

Please explain why it is written like this in the console, thank you heroes

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
大家讲道理

Let me start by saying that I am not a js person, but my intuition tells me that it should be understood this way:

console.log(f ? (b ? "FizzBuzz" : "Fizz") : (b ? "Buzz" : i))

So I don’t think there’s any reason, it’s just that the person who wrote it was lazy and didn’t consider readability.

曾经蜡笔没有小新

You don’t have to write like this

for(var i=1;i<=100;i++){
    var f = i%3 == 0,
        b = i%5 == 0;
    if(f){
        if(b){
            console.log("FizzBuzz");
        }else{
            console.log("Fizz");
        }    
    }else{
       if(b){
           console.log("Buzz");
       }else{
           console.log(i);
       }
    }
}

Looking back, do you find that the above writing method seems easier to read, but the number of lines is a bit too much~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template