DEV Community

Discussion on: JS Coding Patterns that give you away as a Junior Developer

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️
get isSimpson () {
  if (this.lastName === 'Simpson') {
    return true
  }
  return false
}

If anything, I'd say this is worse. Assuming for a moment that it couldn't be simplified further as you do in the article, I think having the else block is preferable because it puts both branches of the decision on the same indentation level and makes it clear that it's either this or that.

If you want to reduce writing and you only have single-statement branches, you could just do

get isSimpson () {
   if (this.lastName === 'Simpson')
      return true
   else
      return false
}

or even put it on 2 lines if the if-condition was a bit shorter.