Back to all reviewers

validate before operations

facebook/react-native
Based on 3 comments
JavaScript

Always explicitly check for null, undefined, or missing properties/methods before performing operations that could fail. JavaScript's loose typing and the fact that `typeof null === 'object'` can lead to runtime errors if values aren't validated first.

Null Handling JavaScript

Reviewer Prompt

Always explicitly check for null, undefined, or missing properties/methods before performing operations that could fail. JavaScript’s loose typing and the fact that typeof null === 'object' can lead to runtime errors if values aren’t validated first.

Key patterns to implement:

  • Check for null/undefined objects: if (params == null) { return; }
  • Verify method existence: if (typeof child.removeParent === 'function') { child.removeParent(this); }
  • Validate array elements: if (_backPressSubscriptions[i] && _backPressSubscriptions[i]()) { ... } or use optional chaining _backPressSubscriptions[i]?.()

This prevents common runtime errors and makes code more robust by handling edge cases where expected values or methods might not be present.

3
Comments Analyzed
JavaScript
Primary Language
Null Handling
Category

Source Discussions