Loading...
Loading...
Core JavaScript fundamentals including variables, data types, operators, control flow, and basic syntax. Essential foundation for all JavaScript development.
npx skill4agent add pluginagentmarketplace/custom-plugin-javascript fundamentalsconst PI = 3.14159; // Immutable binding (preferred)
let count = 0; // Reassignable
var legacy = "avoid"; // Function-scoped (avoid)| Type | Example | typeof |
|---|---|---|
| String | | |
| Number | | |
| Boolean | | |
| Null | | |
| Undefined | | |
| Symbol | | |
| BigInt | | |
| Object | | |
// Arithmetic
+ - * / % **
// Comparison (always use strict)
=== !== > < >= <=
// Logical
&& || !
// Nullish
?? ?.
// Assignment
= += -= *= /= ??= ||= &&=// 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';
}
}// 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// 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| Error | Cause | Fix |
|---|---|---|
| Variable not declared | Check spelling, scope |
| Accessing null/undefined | Use optional chaining |
| Invalid number operation | Validate input types |
Unexpected | Loose equality | Use strict |
// 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;function processNumber(value) {
if (typeof value !== 'number' || Number.isNaN(value)) {
throw new TypeError('Expected a valid number');
}
return value * 2;
}const city = user?.address?.city ?? 'Unknown';
const callback = options.onComplete?.();