Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Why the Unnecessary 'else' after 'return' (no-else-return) error

I always use the else statement. And the data from the Data.js file. Is there something I might have overlooked?

import data from './Data'

function List(props){
  const filteredData = data.filter((el) => {
    if (props.input === '') {
      return el
    } else {
      return el.text.tiLowerCase().includes(props.input)
    }
  })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That's just what the rule requires.

Disallows return before else.

If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.

If you think this rule is worth following, use instead (with correct spelling)

const filteredData = data.filter((el) => {
    if (props.input === '') {
        return el
    }
    return el.text.toLowerCase().includes(props.input)
})

or even better

const filteredData = data.filter((el) => {
    return props.input === ''
        ? el
        : el.text.toLowerCase().includes(props.input)
})

If el will alwys be truthy, then it would make more sense to return true instead.

const filteredData = data.filter((el) => {
    return props.input === ''
        ? true
        : el.text.toLowerCase().includes(props.input)
})

which allows for the simplification to

const filteredData = data.filter((el) => {
    return props.input === '' || !el.text.toLowerCase().includes(props.input)
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!