Use Guards And Fail Fast To Avoid Nested Condition
Topic | Source |
---|---|
๐งน Clean Code | Clean Code - Udemy |
You can avoid deeply nested conditions by using guards. This means you invert the if-condition and return early in this if check. This guard protects the rest of the code, if the condition is not met and avoid it from running.
Guards make it much easier to read code by avoiding deeply nested structures.
if (!email.includes('@')) {
return;
}