ESLint error no-unneeded-trernary

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

Error in get method on return return val ? val : defaultVal; return val ? val : defaultVal; ?

 import ls from 'local-storage'; export default { get(key, defaultVal = null) { var val = ls(key); return val ? val : defaultVal; }, set(key, val) { return ls(key, val); }, remove(key) { return ls.remove(key); }, }; 

Any idea why I am getting this error message? I found some resource on the ESLint website regarding this error message here , but it is applicable to boolean expressions, and I cannot understand why this is applicable to my code ...

+5
source share
1 answer

You won’t need triple code if simple val || defaultVal val || defaultVal .

+20
source

Source: https://habr.com/ru/post/1244122/


All Articles