Langsung ke konten
Skillpedia
Pemrograman umum75k · #3066

type-coercion

Fungsinya

Skill ini meninjau kode JavaScript untuk perbandingan dan konversi yang dapat menghasilkan hasil tak terduga. Skill ini cocok untuk developer yang ingin lebih sedikit bug tersembunyi.

Kapan dipakai

  • ✓Saat kode JavaScript memakai == atau != alih-alih perbandingan ketat.
  • ✓Saat nilai dijumlahkan dengan cara yang mencampur teks dan angka.
  • ✓Saat tinjauan kode meminta penanganan tipe yang lebih jelas dalam sebuah script.

Link skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/type-coercion/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/type-coercion/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

“JavaScript saya kadang membandingkan nilai dengan salah. Bisakah Anda menemukan perbandingan longgar dan menjadikannya ketat?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent menemukan pengecekan kesetaraan longgar dan operasi campuran tipe yang berisiko. Agent menggantinya dengan perbandingan ketat dan konversi yang eksplisit.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Avoid implicit type coercion

JavaScript's implicit type coercion produces results that look like bugs to anyone who doesn't know the exact coercion rules. == comparisons with mixed types silently convert values in ways that fail to catch genuine errors. Explicit conversions make code intent clear and catch real type mismatches at the point where they occur.

Quick Reference

  • Always use === and !== instead of == and !=
  • Convert types explicitly with Number(), String(), Boolean(), parseInt()
  • Be careful with + operator — it concatenates strings but adds numbers
  • Use Array.isArray() instead of typeof for array checks

Check

Find all uses of == and != (non-strict equality) in this file. Also look for implicit type conversions from + operator and other coercion traps.

Fix

Replace all == with === and != with !==. Add explicit type conversions where mixed types are intentionally compared.

Explain

Explain JavaScript's implicit type coercion rules, why == is problematic, and how to write safe type comparisons.

Code Review

Review scripts, client components, and browser execution paths related to Avoid implicit type coercion. 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/type-coercion

Pertanyaan umum

Mengapa == menjadi masalah?

Operator itu mengonversi nilai secara otomatis sebelum membandingkan, sehingga dapat menyembunyikan kesalahan nyata dan membuat hasil sulit diprediksi.

Apa cara yang lebih aman untuk memeriksa array?

Skill merekomendasikan Array.isArray() alih-alih typeof untuk memeriksa array.

Bagaimana tipe sebaiknya dikonversi?

Gunakan fungsi eksplisit seperti Number(), String(), Boolean(), atau parseInt().

Detail

Deskripsi asli dari pembuat

Use when reviewing scripts, client components, bundles, or runtime behavior related to Avoid implicit type coercion. 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
#3066
Lisensi
MIT
Diperbarui
31/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa