π¦ ClawHub
JavaScript
by @ivangdavila
Write robust JavaScript with async patterns, type coercion handling, and modern ES2023+ features.
TERMINAL
clawhub install javascriptπ About This Skill
name: JavaScript slug: javascript version: 1.0.3 description: Write robust JavaScript with async patterns, type coercion handling, and modern ES2023+ features.
When to Use
User needs JavaScript expertise β from core language features to modern patterns. Agent handles async/await, closures, module systems, and ES2023+ features.
Quick Reference
| Topic | File |
|-------|------|
| Async patterns | async.md |
| Type coercion rules | coercion.md |
| Array and object methods | collections.md |
| Modern ES features | modern.md |
Equality Traps
== coerces: "0" == false is true β use === alwaysNaN !== NaN β use Number.isNaN(), not === NaNtypeof null === "object" β check === null explicitly{} === {} is falsethis Binding
this depends on call site β lost in callbacksthis from lexical scope β use for callbackssetTimeout(obj.method) loses this β use arrow or .bind()this is element in regular function, undefined in arrow (if no outer this)Closure Traps
let in loop or IIFE to capture valuevar hoisted to function scope β creates single binding shared across iterationslet per iterationArray Mutation
sort(), reverse(), splice() mutate original β use toSorted(), toReversed(), toSpliced() (ES2023)push(), pop(), shift(), unshift() mutate β spread [...arr, item] for immutabledelete arr[i] leaves hole β use splice(i, 1) to remove and reindexObject.assign are shallow β nested objects still reference originalAsync Pitfalls
await returns Promise, not value β easy to miss without TypeScriptforEach doesn't await β use for...of for sequential asyncPromise.all fails fast β one rejection rejects all, use Promise.allSettled if need all results.catch() or try/catch with awaitNumbers
0.1 + 0.2 !== 0.3 β floating point, use integer cents or toFixed() for displayparseInt("08") works now β but parseInt("0x10") is 16, watch prefixesNumber("") is 0, Number(null) is 0 β but Number(undefined) is NaNBigInt for big numbersIteration
for...in iterates keys (including inherited) β use for...of for valuesfor...of on objects fails β objects aren't iterable, use Object.entries()Object.keys() skips non-enumerable β Reflect.ownKeys() gets all including symbolsImplicit Coercion
[] + [] is "" β arrays coerce to strings[] + {} is "[object Object]" β object toString{} + [] is 0 in console β {} parsed as block, not object"5" - 1 is 4, "5" + 1 is "51" β minus coerces, plus concatenatesStrict Mode
"use strict" at top of file or function β catches silent errorsx = 5 without declaration failsthis is undefined in strict functions β not global objectwith forbiddenβ‘ When to Use
User needs JavaScript expertise β from core language features to modern patterns. Agent handles async/await, closures, module systems, and ES2023+ features.