Posts

Showing posts from June, 2025

nullish coalescing versus logical or

Is this code ok? customer ?. type || '' Probably, but strictly semantically speaking this should use '??' ( nullish coalescing)  instead of '||' The left side condition uses optional chaining which resolves to a value or undefined, ?? is more strict and only fires for null or undefined. Whereas '||' will execute for more values than null or undefined (also 0, false, NaN, '') So if customer.type was 0 then using '||' will resolve to the right side customer ?. type || 'none' // 'none' whereas if customer.type was 0 then using '||' will resolve to the left side customer ?. type || 'none' // 0

ais: the good, the bad, the ugly - the ugly

There are some things AI coding assistants are not good of assisting at this time. But because AI assistants always want to predict, it will. And ais will sound very confident in the prediction. Sometimes the answer can be completely misleading and just garbage. Which is much worse than no answer at all. We recently upgraded our react version and some cypress tests for the app then started failing. I did some investigation and could see an unexpected failing api call in the tests. Why?  I asked the llm for assistance with some context such as new version of react, some libraries, details on the test failure.  It's prediction was a reasonable guess given the prompt but a wrong guess. It suggested a bunch of code changes such as the following: 1. adding timeouts to every cypress element check e.g.   `cy.contains('button', 'Save', { timeout: 10000 }).should('be.visible').click();` 2. new cypress helper functions to handle a double action and then changed tests ...