In JS regular expressions symbols ^ and $ designate start and end of the string. And only with /m modifier (multiline
You can emulate Perl/Python/PCRE \A, which matches at beginning of string but not after a newline, with the Javascript regex ^(?, which translates to English as "match the beginning of a line which has no preceding character".
You can emulate Perl/Python/PCRE \z, which matches only at end-of-string, using (?!(.|\n))$. To get the effect of \Z, which matches only at end-of-string but allows a single newline just before that end-of-string, just add an optional newline: \n?(?!(.|\n))$.