How to replace switch and ternaries in functional JavaScript
Published in
2 min readOct 31, 2018
To branch my code I was leveraging ternaries but there are situations where you either have to go back to imperative conditional statements or start using nested ternaries which may be hard to both write and understand. JavaScript is an amazing language and I have been improving my skills in using declarative expressions and functional programming.
Nested Ternaries
After reading Nested Ternaries are Great article from Eric Elliott, I have been replacing all my conditional statements in my code. Therefore instead of:
I would create nested ternaries: