Using JavaScript to mutate the DOM would not usually be considered cloaking. These days Googlebot can execute JavaScript and sees pages as they are rendered to users once JavaScript has run.
It would still be a bad idea to put high traffic keywords in the HTML source code and then use JavaScript to overwrite them or remove them. That would be like using keywords in white text on a white background or like using keywords in a font too small for users to see. Those are tricks that Googlebot is now advanced enough not to be fooled by, but if you are trying to use them to fool search engines it shows bad faith and could get your site penalized.
Many legitimate frameworks and JavaScript libraries change the DOM because it makes for good user experience. You shouldn't be afraid to use all JavaScript DOM manipulation because you are afraid of cloaking. It should always be fine to add keywords to the page using JavaScript, or change content on user interaction.
Cloaking is usually caused by changing the content or keywords based on the User-Agent
string, showing special content just when the Googlebot
user agent is present. See Cloaking - Search Console Help.