ESLint error no-unneeded-ternary

前端 未结 2 1762
时光取名叫无心
时光取名叫无心 2021-02-11 20:32

ESLint is telling me this error message inside my JS module: error no-unneeded-ternary Unnecessary use of conditional expression for default assignment

相关标签:
2条回答
  • 2021-02-11 20:48
    // Bad
    foo(bar ? bar : 1);
    
    // Good
    foo(bar || 1);
    

    This is how they say in Es-lint

    0 讨论(0)
  • 2021-02-11 21:00

    You don't need a ternary when a simple val || defaultVal will do.

    0 讨论(0)
提交回复
热议问题