Return result from Ternary in one line (JavaScript)

前端 未结 3 644
旧时难觅i
旧时难觅i 2021-01-29 16:09

In JavaScript, rather than having to assign the result to a variable, is it possible to return the result of a ternary in one line of code?

e.g. Instead of

3条回答
  •  野的像风
    2021-01-29 16:32

    Yes. It's possible. Also you can make your code even more compact.

    function isAGreaterThanB(){
        return a > b;
    }
    

    Above code will return true if a is greater, false if not.

提交回复
热议问题