{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiggtmqn76gvzdbfiwtjbxycso3rak7lxfoovxvryb7uykaidmpqxi",
    "uri": "at://did:plc:vyjlfm46mfv6u4vjp6qtrfx2/app.bsky.feed.post/3mnfq7qemjlb2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreidg2k33tiuupnstmiowh7hyyvtsbe3gyhfygiytrzynysnhoctrxi"
    },
    "mimeType": "image/jpeg",
    "size": 81260
  },
  "path": "/articles/coerce-the-truth-out-of-you",
  "publishedAt": "2026-06-03T06:30:00.000Z",
  "site": "https://thedailywtf.com",
  "tags": [
    "CodeSOD",
    "Utilize BuildMaster",
    "Download"
  ],
  "textContent": "**Frank** suspected something odd when he spotted a use of React's `useMemo` function in some JavaScript code. Now, there's nothing _wrong_ with using that method, in and of itself. It watches some variables and recalculates a callback if they change for any reason. It's a great tool for when you want to avoid recalculating expensive things over and over again.\n\nBut in this case, the calculation in question was `isAuthorized`, which wasn't an expensive calculation; it was just checking if certain values are set. The code looked like this:\n\n\n      const isAuthorized = useMemo(() => {\n        return (session && token && !group) === false;\n      }, [session, token, group]);\n\n\n`session`, `token` and `group` are all either going to be null, or be an object. To be authorized, all three must be set to non-null values. A rational person, knowing this, might choose to `return session && token && group`, and exploit JavaScript's truthiness. Or, if you really wanted to coerce it to a boolean, you could `return !!(session && token && group)`.\n\nSo why on Earth are they negating `group`? How would this even work? If the check is \"all three must be set\" what is this doing?\n\nWell, if you do `a && b && c`, JavaScript will return the last value you looked at. The `&&` operator short circuits, so that means it either returns the first falsy value you encounter, _or_ the very last value in the chain.\n\nSo in this scenario: `(session && token && !group)`, if `session` or `token` is `null`, the expression evaluates to `null`. Otherwise, if `group` is `null`, then `!group` will evaluate to `true`. Because they use the `===` operator, JavaScript won't do any type coercion, and that means `null === false` is false, as is `true === false`.\n\nI can't believe that this code works as _intended_. I mean, it works, it gives the correct output, but I think that's an accident. Happenstance of someone with no clue gradually throwing operators into an expression until it does what they want. Perhaps it's LLM generated code- who can even guess anymore? It certainly seems like it was generated through a stochastic process; whether that's a bumbling developer or a bunch of math, there's definitely no _intelligence_ involved, artificial or otherwise.\n\n[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!",
  "title": "CodeSOD: Coerce the Truth Out of You"
}