Hi,
The difference between Javascript and PHP is that Javascript is a client-side scripting language and PHP is a server-side scripting language, what allows it to easily log error messages into file on server.
Because javascript is running on client side it is difficult to get error messages and save them into file. When a javascript error occurs, it usually stops the script execution, so you can see that some features on website are not working as expected.
Simple way how to see javascript errors is to open a Console in a web browser and run the script or reload the website.
Another option how to find an error is to use alert() function.
These two options are suitable when you are trying to find a javascript error using your PC. But when you need to get an error, that occurs on website visitor's side, you can try to create a script, that will check its running and when there will be an error, it will use Ajax, which allows to log errors to file on server.