ESLint error no-unneeded-ternary

前端 未结 2 1371
悲哀的现实
悲哀的现实 2021-02-11 20:25

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 21:02
    // Bad
    foo(bar ? bar : 1);
    
    // Good
    foo(bar || 1);
    

    This is how they say in Es-lint

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

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

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