Langsung ke konten
Skillpedia
Website & UI (frontend)75k · #2781

const-let

Fungsinya

Skill ini memeriksa JavaScript untuk deklarasi var dan menyarankan const atau let sebagai gantinya. Cocok untuk pengembang yang menginginkan kode yang lebih aman dan mudah dibaca.

Kapan dipakai

  • ✓Saat Anda menemukan var dalam file JavaScript lama.
  • ✓Saat sebuah variabel tampaknya bisa diakses di tempat yang seharusnya tidak bisa.
  • ✓Saat Anda meninjau kode untuk kejelasan sebelum rilis.

Link skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/const-let/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/const-let/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Telusuri skrip ini dan ganti setiap var dengan const atau let.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent mendaftar setiap deklarasi var beserta nomor barisnya, lalu memakai const untuk nilai yang tidak pernah berubah dan let untuk nilai yang ditetapkan ulang.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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

Pertanyaan umum

Mengapa var berisiko?

Skill menyatakan var memiliki function scope dan hoisting, yang dapat menyebabkan bug halus.

Kapan saya sebaiknya memakai const?

Ketika variabel tidak pernah ditetapkan ulang.

Apakah const membuat objek tidak bisa diubah?

Tidak. Skill mencatat bahwa objek dan array yang dideklarasikan dengan const tetap bisa diubah.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
75k
Peringkat
#2781
Lisensi
MIT
Diperbarui
31/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa