Javascript is a proprietary language from Microsoft that will only work correctly on Microsoft browsers.
You go to an existing website & copy the code of an effect you like, or, better, go to a library of Javascript scripts where they will be properly annotated & explained.
NB Javascript often fails through TS firewalls...