js-early-exit

Early Return from Functions

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "js-early-exit" with this command: npx skills add theorcdev/8bitcn-ui/theorcdev-8bitcn-ui-js-early-exit

Early Return from Functions

Return early when result is determined to skip unnecessary processing. This optimization is especially valuable when the skipped branch is frequently taken or when the deferred operation is expensive.

Incorrect (processes all items even after finding answer):

function validateUsers(users: User[]) { let hasError = false let errorMessage = ''

for (const user of users) { if (!user.email) { hasError = true errorMessage = 'Email required' } if (!user.name) { hasError = true errorMessage = 'Name required' } // Continues checking all users even after error found }

return hasError ? { valid: false, error: errorMessage } : { valid: true } }

Correct (returns immediately on first error):

function validateUsers(users: User[]) { for (const user of users) { if (!user.email) { return { valid: false, error: 'Email required' } } if (!user.name) { return { valid: false, error: 'Name required' } } }

return { valid: true } }

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

fumadocs-mdx-structure

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

rendering-animate-svg

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

8-bit-pixel-art-patterns

No summary provided by upstream source.

Repository SourceNeeds Review