Tags

Conditionals

Conditionals

0 lessons
3 code snippets
1 question bank

conditionals

Code Snippets

3 snippets
Code Snippet

every, some, and Includes Patterns

When you need to ask "do all of these match?" or "is there at least one match?", `Array.prototype.every` and `Array.prototype.some` give you boolean answers in one pass. This snippet covers those two plus the count-via-filter pattern for "how many match?" and a small predicate factory pattern that lets you compose these checks for form validation, feature flags, or permission rules.

JavaScript
arrays
map-filter-reduce
conditionals

703

10

Easy
Code Snippet

Value-In-Array and Value-In-Object Checks

"Is X in this array?" and "is X anywhere in this object?" sound like the same question but call for different tools. Arrays have `includes` (which handles `NaN`), `indexOf` (which does not), and `Set.has` for hot paths. Objects need `Object.values` for a flat scan and a recursive walk for nested structures. This snippet covers both, with the gotchas that bite: `NaN`, hot-path scans, and shared object identity.

JavaScript
arrays
references
conditionals

605

13

Easy
Code Snippet

React Conditional Rendering Patterns

Conditional rendering in React looks easy until the `0`-falsy-render bug ships to production. This snippet covers the three patterns you should reach for in order: a ternary in JSX for either-or branches, the `&&` short-circuit (with the famous `0` gotcha and its fix), and an early-return plus extracted helper component when the branching gets dense. Examples render a small text representation of the output so the teaching is independent of any JSX compiler.

JavaScript
react
hooks
conditionals

806

25

Easy