This repository demonstrates a common error in JavaScript: forgetting to explicitly check for null or undefined values as function inputs.
The bug.js file shows a simple addition function that is vulnerable to errors if null values are passed. The bugSolution.js demonstrates the corrected function which uses appropriate null checks to avoid these errors.
- Clone this repository.
- Open the
bug.jsandbugSolution.jsfiles in your favorite code editor. - Run the
bug.jsto see the error behavior. - Observe that the
bugSolution.jshandles null values gracefully.
This example highlights the importance of defensive programming and how simple null checks can prevent significant problems in your applications.