Skip to content

This code demonstrates how to handle null values in JavaScript functions. A common error is forgetting to check for null or undefined inputs, leading to unexpected behavior or runtime errors. This example showcases safe null handling.

Notifications You must be signed in to change notification settings

Bug-Hunter-X/JavaScript-Null-Handling-in-Functions-hm7fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

JavaScript Null Handling in Functions

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.

How to run

  1. Clone this repository.
  2. Open the bug.js and bugSolution.js files in your favorite code editor.
  3. Run the bug.js to see the error behavior.
  4. Observe that the bugSolution.js handles null values gracefully.

This example highlights the importance of defensive programming and how simple null checks can prevent significant problems in your applications.

About

This code demonstrates how to handle null values in JavaScript functions. A common error is forgetting to check for null or undefined inputs, leading to unexpected behavior or runtime errors. This example showcases safe null handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published