All skills
sergiodxa avatar

/frontend-js-best-practices

@2987820

JavaScript performance optimization guidelines. Use when writing, reviewing, or refactoring JavaScript/TypeScript code to ensure optimal performance patterns. Triggers on tasks involving loops, data structures, DOM manipulation, or general JS optimization.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-js-best-practices

This session only. Nothing lands on disk.

rulesconst-let-usage.md

≈562 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Const vs Let Usage

Use const at module level and let inside functions/blocks.

Module Level: Always const

// Single value constants - UPPER_SNAKE_CASE
const MAX_RETRIES = 3;
const DEFAULT_TIMEOUT = 5000;
const API_BASE_URL = "/api/v1";

// Objects, arrays, Maps, Sets - camelCase
const userCache = new Map<string, User>();
const allowedRoles = new Set(["admin", "editor"]);
const defaultConfig = { timeout: 5000, retries: 3 };

// Regex patterns - UPPER_SNAKE_CASE
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const SLUG_PATTERN = /^[a-z0-9-]+$/;

Inside Functions/Blocks: Always let

function processUsers(users: User[]) {
  // Always use let inside functions, even for values that don't change
  let total = 0;
  let activeCount = 0;
  let result = [];

  for (let user of users) {
    let isActive = user.status === "active";
    if (isActive) {
      activeCount += 1;
      result.push(user);
    }
    total += 1;
  }

  let summary = { total, activeCount };
  return { result, summary };
}

Why This Convention

  1. Clear scope distinction - const signals module-level, let signals local
  2. Easier refactoring - No need to change const to let when you need to reassign
  3. Consistent codebase - One rule to follow, no debates about const vs let locally
  4. UPPER_SNAKE_CASE - Instantly identifies true constants (primitives that never change)

Never Use var

// Bad
var count = 0;
var users = [];

// Good
let count = 0;
let users = [];

Summary

Scope Keyword Naming
Module-level primitive constants const UPPER_SNAKE_CASE
Module-level objects/arrays/Maps/Sets const camelCase
Module-level functions function declaration camelCase
Inside functions/methods/blocks let camelCase

Source: SKILL.md on GitHub

1 warning13d5 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    The skill provides a comprehensive set of JavaScript and TypeScript performance and style guidelines. No security issues were detected.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

  • Runlayer7mo

    19/19 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 2987820. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-js-best-practices