本文へスキップ
Skillpedia
WebサイトとUI(フロントエンド)75k · #2781

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がスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/const-let/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

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.

repo: thedaviddias/Front-End-Checklist

人気

GitHubのスター
75k
ランキング
#2781
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル