Google can execute JavaScript, but with a delay and within limits: content or links that only appear after execution may be indexed late, or not at all.
Most AI crawlers, however, do not execute JavaScript. Content present in the HTML delivered by the server remains the safest way to be read by all.