Agent skill
fundamentals
Core JavaScript fundamentals including variables, data types, operators, control flow, and basic syntax. Essential foundation for all JavaScript development.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/fundamentals
SKILL.md
JavaScript Fundamentals Skill
Quick Reference Card
Variable Declaration
const PI = 3.14159; // Immutable binding (preferred)
let count = 0; // Reassignable
var legacy = "avoid"; // Function-scoped (avoid)
8 Data Types
| Type | Example | typeof |
|---|---|---|
| String | "hello" |
"string" |
| Number | 42, 3.14, NaN |
"number" |
| Boolean | true, false |
"boolean" |
| Null | null |
"object" |
| Undefined | undefined |
"undefined" |
| Symbol | Symbol('id') |
"symbol" |
| BigInt | 9007199254740991n |
"bigint" |
| Object | {}, [], fn |
"object" |
Operators Cheat Sheet
// Arithmetic
+ - * / % **
// Comparison (always use strict)
=== !== > < >= <=
// Logical
&& || !
// Nullish
?? ?.
// Assignment
= += -= *= /= ??= ||= &&=
Control Flow Patterns
// Early return (preferred)
function validate(input) {
if (!input) return { error: 'Required' };
if (input.length < 3) return { error: 'Too short' };
return { valid: true };
}
// Switch with exhaustive handling
function getColor(status) {
switch (status) {
case 'success': return 'green';
case 'warning': return 'yellow';
case 'error': return 'red';
default: return 'gray';
}
}
Type Coercion Rules
// Explicit conversion (preferred)
Number('42') // 42
String(42) // "42"
Boolean(1) // true
// Truthy values: non-zero numbers, non-empty strings, objects
// Falsy values: 0, "", null, undefined, NaN, false
Modern Operators
// Nullish coalescing
const name = input ?? 'Guest'; // Only null/undefined
// Optional chaining
const city = user?.address?.city; // Safe navigation
// Logical assignment
config.debug ??= false; // Assign if nullish
Troubleshooting
Common Issues
| Error | Cause | Fix |
|---|---|---|
ReferenceError: x is not defined |
Variable not declared | Check spelling, scope |
TypeError: Cannot read property |
Accessing null/undefined | Use optional chaining ?. |
NaN result |
Invalid number operation | Validate input types |
Unexpected true/false |
Loose equality == |
Use strict === |
Debug Checklist
// 1. Check type
console.log(typeof variable);
// 2. Check value
console.log(JSON.stringify(variable));
// 3. Check for null/undefined
console.log(variable === null, variable === undefined);
// 4. Use debugger
debugger;
Production Patterns
Input Validation
function processNumber(value) {
if (typeof value !== 'number' || Number.isNaN(value)) {
throw new TypeError('Expected a valid number');
}
return value * 2;
}
Safe Property Access
const city = user?.address?.city ?? 'Unknown';
const callback = options.onComplete?.();
Related
- Agent 01: JavaScript Fundamentals (detailed learning)
- Skill: functions: Function patterns
- Skill: data-structures: Objects and arrays
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?