本文へスキップ
Skillpedia
一般的なプログラミング75k · #3066

type-coercion

できること

このスキルは、思わぬ結果を生むおそれのある比較や変換を JavaScript のコードで確認します。隠れたバグを減らしたい開発者向けです。

使う場面

  • ✓JavaScript のコードで、厳密でない == や != を使っているとき。
  • ✓テキストと数値を、意図しない形で足し合わせているとき。
  • ✓スクリプトの型の扱いを、もっと明確にするようコードレビューで求められたとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

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

AIへの頼み方の例

“私の JavaScript は、ときどき値の比較を誤ります。緩い比較を見つけて、厳密な比較に直してもらえますか。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、緩い等価比較と、危険な型の混在した演算を見つけます。それらを厳密な比較と、明示的な変換に置き換えます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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

よくある質問

== はなぜ問題なのですか?

比較の前に値を自動的に変換するため、本当の間違いを隠し、結果を予測しにくくするからです。

配列かどうかを確かめる安全な方法は何ですか?

typeof ではなく Array.isArray() を使うことを、このスキルは勧めています。

型はどのように変換すべきですか?

Number()、String()、Boolean()、parseInt() などの明示的な関数を使うべきです。

詳細

作者による元の説明

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

人気

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

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

0

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

コメント

  • …

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

似ているスキル