Google’s John Mueller said in a Reddit thread that Google will typically use the most restrictive crawling command or signals they find on the page. “Google will use the most restrictive setting you have on the page,” John Mueller said. It doesn’t matter if Google found it via HTML or JavaScript, assuming Google can find it.
Here is what John Mueller said:
See that last line? If you add a nofollow using JavaScript, Google would honor that. If you add JavaScript to remove the nofollow from the code, Google won’t honor that.
Google goes with the most restrictive signal they get here.