Skip to content

Add examples for pure functions and destructuring defaults #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mohandand
Copy link

This PR adds two new best-practice examples to the guide:

  1. Pure Functions vs. Side Effects (in the Functions section)

    • Demonstrates the importance of avoiding side effects
    • Includes good vs. bad examples with clear reasoning
  2. Destructuring Defaults & Nested Destructuring (in the Objects and Data Structures section)

    • Shows how to provide safe defaults and avoid runtime errors
    • Includes clean parameter handling with modern syntax

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section provides a clear and concise explanation of the difference between pure functions and side effects, with practical examples to illustrate both good and bad practices. The examples are especially effective in demonstrating why pure functions are preferable—highlighting predictability, testability, and ease of refactoring. The "bad" code block effectively showcases common pitfalls like mutating external state, while the "good" example demonstrates clean and functional code by returning new values instead of modifying existing ones. The added inline comments are helpful for reinforcing key points. Overall, this is a solid addition to your documentation or GitHub README—well-structured, informative, and easy to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants