const-let
できること
このスキルは、JavaScriptのvar宣言を確認し、代わりにconstまたはletを提案します。より安全で読みやすいコードを求める開発者向けです。
使う場面
- ✓古いJavaScriptファイルにvarがあるとき。
- ✓変数が、アクセスされるべきでない場所からアクセスできるように見えるとき。
- ✓公開の前に、明確さのためにコードをレビューしているとき。
スキルのリンク
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/const-let/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このスクリプトを確認し、すべてのvarをconstまたはletに置き換えてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、すべてのvar宣言を行番号とともに一覧にし、変わらない値にはconstを、再代入される値にはletを使います。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Prefer const and let over var
var'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 — const signals that a binding should not be reassigned, which helps readers understand data flow.
Quick Reference
- Use const for values that are never reassigned
- Use let when reassignment is needed
- Never use var — it has function scope and is hoisted, causing subtle bugs
- const does not mean immutable — objects and arrays declared with const can still be mutated
Check
Scan this JavaScript file for any use of var and flag every occurrence with line numbers.
Fix
Replace all var declarations with const or let as appropriate. Use const when the variable is never reassigned, let otherwise.
Explain
Explain why const and let are preferred over var, covering scope, hoisting, and temporal dead zone.
Code Review
Review 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.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/const-let
よくある質問
varは、なぜ危険ですか?
varには関数スコープと巻き上げがあり、微妙なバグを起こすおそれがあると、このスキルは説明しています。
constはいつ使うべきですか?
変数が再代入されない場合です。
constを使うと、オブジェクトは変更できなくなりますか?
いいえ。constで宣言されたオブジェクトや配列は、依然として変更できると、このスキルは注記しています。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 75k
- ランキング
- #2781
- ライセンス
- MIT
- 更新日
- 2026/10/31
コメント
- …
このリポジトリの他のスキル
frontendchecklist
75kコマンドラインツールを使って、フロントエンドのコードとライブページを、アクセシビリティ、速度、SEO、セキュリティに関する380以上のルールと照らし合わせて確認します。
frontend-checklist-global
75kフロントエンドのプロジェクトを、386のFront-End Checklistのルールすべてと照らし合わせて監査し、見つかった問題ごとに具体的な修正方法を示します。
404-page
75k見つからないページの画面に役立つリンクがあり、本物の404ステータスを返すかを確認し、迷った訪問者が目的のページを見つけられるようにします。
about-page
75kサイトの運営者が誰かを説明する、分かりやすいAboutページがあるかを確認し、訪問者と検索エンジンからの信頼を高めます。
似ているスキル
angular-developer
280kエージェントがAngularのコードを作成し、プロジェクト構成についてアドバイスできるようにします。新しいプロジェクトの開始、コード部品の作成、パフォーマンスやアクセシビリティの改善に役立ちます。
frontend-a11y
280kエージェントが Web インターフェースを誰にとっても使いやすくするよう支援します。スクリーンリーダーやキーボード操作に対応し、サイトやアプリが適切に動作するようにします。
frontend-patterns
280kエージェントがフロントエンド開発の最新パターンを適用できるようにします。React と Next.js において、パフォーマンスの最適化、状態管理、ベストプラクティスの遵守を行います。