guard condition nodejs code example
Example: javascript guard clause
//A good example of using a guard clause is on IF statements
//Example:
//Here is a normal if function:
let x = 0
if (x <= 0) {
//codes here
} else {
//more codes here
};
//But there are a lot of potential bugs in that code.
//Here is an example of a guard clause:
let x = 0;
if (x <= 0) return //codes / or empty
if (x > 0) return //codes here
//It lets you write more compact codes, and potentially easier to read