Diferans ant `==` ak `===` an JavaScript

asked 4 months ago563 viewsht

4

Pwofesè m di m pou m toujou itilize ===, men li pa eksplike poukisa. Kisa == fè ki danjere konsa?

AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

asked 4 months ago

1 Answer

8
✓
✓ Accepted answer

== fè konvèsyon tip otomatik anvan li konpare. === pa fè sa: tip yo ak valè yo dwe egal.

0 == ''        // true  (!)
0 == '0'       // true
'' == '0'      // false (pa transitif!)
null == undefined // true

0 === ''       // false
0 === '0'      // false

Rezilta == yo difisil pou prevwa, e se konsa bug kache antre nan kòd la. Règ senp: toujou itilize === ak !==.

Sèl eksepsyon anpil moun aksepte: x == null pou teste null oswa undefined an menm tan.

Sign in to tell others whether this worked.

answered 4 months ago

Sign in and verify your email to post an answer.