Sum distances with a Euclidean norm
A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.
Developer journal
Patterns for transforming data, managing asynchronous work and writing browser code.
A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.
Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.
A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.
Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.
Replacing just the first delimiter leaves mixed formatting in an identifier. replaceAll makes the intended scope explicit.
JSON text and transport bytes are separate representations. Encode the text as UTF-8 before measuring or sending a byte payload.
String length counts UTF-16 units. A for-of loop advances by Unicode code point, which keeps a supplementary character together.
JavaScript's remainder can be negative. Normalize a bearing into one full turn before choosing a compass label.
A missing preference and a deliberately disabled preference need different defaults. Nullish coalescing keeps valid false and zero values.
Cash rounding belongs at the payment boundary. Working in cents makes a five-cent increment easier to reason about.
A clock time after midnight may belong to yesterday's shift. Compare the interval endpoints before calculating its duration.
Capitalization depends on the language of the text. Pass the intended locale at the boundary where a display label is created.
Array indexes are useful when a value occurs twice. entries() keeps the position and the value together while the loop advances.
Removing combining marks can make a secondary search index more forgiving. Preserve the original spelling in display and storage.
Repeated URL keys carry multiple selections. Reading a single value can silently discard filters chosen by the visitor.
Batching work by array slices gives the last batch permission to be shorter. Guard the requested size before using it as the loop increment.
Use every when the question is whether any record violates a rule. It stops at the first failure and accepts an empty list.
The Euclidean algorithm reduces a pair by taking successive remainders. Each step produces a smaller divisor until the remainder reaches zero.
A URL parser exposes the canonical host representation of an internationalized name. Keep display text separate from comparison keys.
Awaiting an already fulfilled promise still yields control to the microtask queue. That matters when debugging the order of UI updates.
A curried function lets one call establish a policy and later calls supply the values. The returned function retains its first argument.
Choose the flattening depth from the data contract. Flattening another level can erase a meaningful grouping.
Set preserves insertion order and collapses repeated primitive values. Objects still compare by reference.
A folded sheet contributes four printed pages. Padding a booklet is a remainder calculation, with zero padding when the count already fits.
A numeric field can contain NaN or infinity even after it has become a number. Number.isFinite checks the value without coercing a string.
A promise controlled by a callback bridges two styles of API. Keep its resolve and reject functions scoped to the operation that owns them.
A radix changes how an integer is written. The numeric value stays the same while its string representation changes.
An instanceof check tests a constructor relationship. Deserialized records do not automatically regain the class prototype.
A nested lexical binding can hide an outer value without mutating it. Logging before and after the block reveals which value each reader sees.
Freezing a settings object locks its own properties. A referenced nested array or object can still change.