ESLint: no-unneeded-ternary error

JavaScript

On this code lines I get an error from ESLint. The code works but ESLint is throwing an error. This code lines should toggle my boolean value.

var show = false;

function toggleVisible () {
   return show ? false : true;
}

Error:

error Unnecessary use of boolean literals 
in conditional expression no-unneeded-ternary
Web pages Question created: 2020-05-15 09:09 SpelunkiRU

2

The error comes up because you are using a short hand statement which is not needed here. Simply try it this way by using boolean negation:

var show = false;

function toggleVisible () {
   return !show;
}
answered 2020-05-17 09:13 BenFlake