Tag

Loose Equality

1 views collected around this technical thread.

IT Services Circle
IT Services Circle
Sep 17, 2024 · Frontend Development

Why [] == ![] in JavaScript: Understanding Loose Equality and Its Pitfalls

This article explains the surprising result of the JavaScript expression [] == ![], detailing how empty arrays are truthy, how they are coerced to strings and numbers during loose equality comparison, and why using strict equality (===) or TypeScript avoids such confusing behavior.

Loose EqualityProgrammingStrict Equality
0 likes · 4 min read
Why [] == ![] in JavaScript: Understanding Loose Equality and Its Pitfalls
政采云技术
政采云技术
Jun 21, 2022 · Frontend Development

How to Make the Expression x == 1 && x == 2 && x == 3 True in JavaScript

This article explains how to satisfy the JavaScript expression x == 1 && x == 2 && x == 3 by understanding the differences between loose (==) and strict (===) equality, type coercion rules, and implementing custom valueOf or toString methods on objects to increment a counter during each comparison.

EqualityLoose Equalityjavascript
0 likes · 9 min read
How to Make the Expression x == 1 && x == 2 && x == 3 True in JavaScript