DEV Community 👩‍💻👨‍💻

Discussion on: Improve your JS skills with those tips #1

Collapse
manoharreddyporeddy profile image
Manohar Reddy Poreddy
I have seen this multiple time :
    if (...) { // the condition is not important in this example
      return 'toto'
    } else {
      return 'tutu'
    }

If your if return value you can just replace the code above by :

    if (...) { // the condition is not important in this example
      return 'toto'
    }

    return 'tutu'
Enter fullscreen mode Exit fullscreen mode

should it be below ?

return (...) ? 'toto': 'tutu' ;
Enter fullscreen mode Exit fullscreen mode
Collapse
codeoz profile image
CodeOz Author

hey thanks for your comment, yes it's working in case of you only need to return something! If you add more logic in the if or after you cannot use ternary (unlike you create function).

The other point is about else if! If you need to have else if is more complicated!