Deep JavaScript language mechanics from "You Don't Know JS" philosophy. Use for debugging closures, this binding, prototype chains, coercion bugs, or async execution mysteries. Triggers on complex JS runtime behavior, scope issues, "why does JavaScript do this?", unexpected this binding.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Deep JavaScript language mechanics from "You Don't Know JS" philosophy. Use for debugging closures, this binding, prototype chains, coercion bugs, or async execution mysteries. Triggers on complex JS runtime behavior, scope issues, "why does JavaScript do this?", unexpected this binding.
Kyle Simpson (YDKJS) JavaScript Philosophy
Deep JavaScript language mechanics expertise based on Kyle Simpson's "You Don't Know JS" philosophy. Understanding what JavaScript actually does under the hood - closures, scope, this binding, prototypes, coercion, and async patterns at the engine level.
Applying Kyle Simpson's deep JavaScript philosophy when debugging complex runtime behavior, understanding scope chain resolution, diagnosing this binding issues, explaining prototype delegation, or when abstraction leaks cause unexpected behavior. Use this when surface-level JavaScript knowledge is insufficient and true language mechanics understanding is required.
Triggers:
Complex closure debugging or memory leak investigation
Know the language, not just the patterns - Understand WHY code works, not just that it works
Embrace JavaScript as it is - Don't fight the language; understand its design decisions
Abstraction leaks are bugs in understanding - When abstractions fail, language knowledge saves you
Mental models must match engine behavior - Your understanding should predict what JavaScript will do
The Three Pillars
Scope & Closures
Lexical scope is determined at author time, not runtime
Closures are functions that remember their lexical scope
The scope chain is a one-way lookup (inner → outer)
Block scope (let/const) vs function scope (var)
this & Object Prototypes
this is determined by call-site, not definition site
Four rules in order: new > explicit > implicit > default
Prototype is delegation, not inheritance (objects link to other objects)
[[Prototype]] chain lookup happens on property access
Types & Coercion
JavaScript has types; variables don't have types, values do
Coercion is not evil; implicit coercion can be readable when understood
== uses coercion, === doesn't - know when each is appropriate
Falsy values: false, 0, -0, 0n, "", null, undefined, NaN
Diagnostic Framework
Debugging this Binding
// Ask these questions in order:// 1. Was the function called with `new`? → this = newly constructed object// 2. Was it called with call/apply/bind? → this = specified object// 3. Was it called with a context object? → this = that object// 4. None of the above? → this = undefined (strict) or globalThis (sloppy)// Arrow functions: lexical this (inherits from enclosing scope)
Debugging Closures
// Closure = function + its lexical environment// Common gotcha: loop variable capture// Bug:for (var i = 0; i < 3; i++) {
setTimeout(() =>console.log(i), 100); // prints 3, 3, 3
}
// Fix 1: let creates new binding per iterationfor (let i = 0; i < 3; i++) {
setTimeout(() =>console.log(i), 100); // prints 0, 1, 2
}
// Fix 2: IIFE creates new scopefor (var i = 0; i < 3; i++) {
((j) =>setTimeout(() =>console.log(j), 100))(i);
}
Debugging Prototype Chain
// Object.create(proto) - creates object with [[Prototype]] = proto// obj.hasOwnProperty(prop) - checks own properties only// prop in obj - checks entire prototype chain// Object.getPrototypeOf(obj) - gets [[Prototype]]// Shadowing: own property hides prototype property// Delegation: property lookup walks up [[Prototype]] chain
Was `new` used?
├─ Yes → this = new object
└─ No → Was call/apply/bind used?
├─ Yes → this = specified object (unless null/undefined in strict)
└─ No → Is there a context object (obj.fn())?
├─ Yes → this = context object
└─ No → Is it strict mode?
├─ Yes → this = undefined
└─ No → this = globalThis
Arrow function? → Inherits this from enclosing scope (lexical)
Anti-Patterns to Recognize
Misunderstanding Hoisting
// Mental model: declarations move to top, assignments stay// Reality: functions fully hoisted, var declarations hoisted (value undefined)console.log(foo); // undefined (var hoisted)console.log(bar); // ReferenceError (let TDZ)var foo = 1;
let bar = 2;
Confusing Prototype with Class Inheritance
// JavaScript has delegation, not classical inheritance// Objects delegate to other objects via [[Prototype]]// Class syntax is syntactic sugar over prototype delegation// This is NOT copying properties:classChildextendsParent {}
// This is linking Child.prototype.[[Prototype]] = Parent.prototype
Relying on Implicit Globals
// In sloppy mode, undeclared assignment creates globalfunctionleak() {
oops = "I'm global now"; // No var/let/const = global property
}
// Always use strict mode: "use strict";
Debugging Checklist
When JavaScript behaves unexpectedly:
What is this at the call-site? (Not definition site)
Is there a closure capturing a variable? What's its current value?
Is coercion happening? What types are actually involved?
Is the prototype chain being traversed? Check hasOwnProperty
Is this sync or async? What's the event loop state?
Am I in strict mode? Behavior differs significantly
Is TDZ (Temporal Dead Zone) involved with let/const?