{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-const-let-ab13425719c5","title":"Prefer const and let over var in JavaScript","summary":"Review JavaScript code to identify and replace var declarations with const or let, improving scope control and reducing bugs. The deliverable is a list of var occurrences with line numbers and suggested replacements.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-const-let-ab13425719c5","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-const-let-ab13425719c5","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-const-let-ab13425719c5.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-const-let-ab13425719c5\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before reviewing, ensure the code is transpiled to ES6 or higher. When replacing var with const, check if the variable is reassigned; if not, use const, otherwise use let. Document any object or array mutations that occur after declaration with const.","instructions":"---\nname: const-let\ndescription: \"Use when reviewing scripts, client components, bundles, or runtime behavior related to Prefer const and let over var. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.\"\nmetadata:\n  category: javascript\n  priority: high\n  difficulty: beginner\n  estimatedTime: \"10\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/javascript\/const-let\n---\n\n# Prefer const and let over var\n\nvar's function scope and hoisting behavior regularly causes bugs where variables are accessible outside the block they were declared in. const and let enforce block scope and make code intent clearer \u2014 const signals that a binding should not be reassigned, which helps readers understand data flow.\n\n## Quick Reference\n\n- Use const for values that are never reassigned\n- Use let when reassignment is needed\n- Never use var \u2014 it has function scope and is hoisted, causing subtle bugs\n- const does not mean immutable \u2014 objects and arrays declared with const can still be mutated\n\n## Check\n\nScan this JavaScript file for any use of var and flag every occurrence with line numbers.\n\n## Fix\n\nReplace all var declarations with const or let as appropriate. Use const when the variable is never reassigned, let otherwise.\n\n## Explain\n\nExplain why const and let are preferred over var, covering scope, hoisting, and temporal dead zone.\n\n## Code Review\n\nReview scripts, client components, and browser execution paths related to Prefer const and let over var. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/javascript\/const-let\n","use_cases":["Reviewing scripts for var usage and replacing with const or let","Auditing client components for scope-related bugs","Fixing runtime behavior issues caused by var hoisting"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/const-let\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-23","created_at":"2026-11-22T15:35:41.000000Z","updated_at":"2026-11-23T04:54:56.000000Z","seo_title":"Prefer const and let over var in JavaScript","seo_description":"Review and refactor JavaScript code to replace var with const or let for better scope control and bug prevention.","seo_keywords":["JavaScript const let best practices","Replace var with const in JavaScript","JavaScript scope and hoisting","Fix var bugs in frontend code"]}}