DEV Community

loading...

Discussion on: 5 ways to refactor if/else statements in JS functions

Collapse
greenroommate profile image
Haris Secic

Since your shorting out the code I expected something like

let noElseReturns = (str) => {
  if (typeof str == "string" && str.length > 1) {
      return str.slice(0,-1)
  }
  return null
}
Enter fullscreen mode Exit fullscreen mode
Collapse
sylwiavargas profile image
Sylwia Vargas Author

yeah, that totally works too! Thanks for this comment!
I always try to balance how much I'm shortening the code vs how long the blog post is as my blogs posts are oftentimes read by folks with not much programming experience. Sometimes, I prefer to introduce changes incrementally or even not to introduce something because I also trust that the readers (just like yourself) would dig more or even find better solutions ✨