April 2018
Intermediate to advanced
284 pages
5h 46m
English
| Tip 19 | Maximize Efficiency with Short Circuiting |
In this tip, you’ll learn to reduce conditionals to the smallest possible expression with short circuiting.
You’ve been simplifying conditional expressions a lot in the last few tips. But there’s one more level of simplification you can use: short circuiting.
As the name implies, the goal of short circuiting is to bypass information checks by placing the most relevant information first.
Consider the following ternary, which would fit in well with the discussion from the previous chapter.
| | function getIconPath(icon) { |
| | const path = icon.path ? icon.path : 'uploads/default.png'; |
| | return `https://assets.foo.com/${path}`; |
| | } |
The goal here is fairly ...
Read now
Unlock full access