How to get Javascript error messages - log errors to file ?

How can I get Javascript error messages to see where is the problem, so I can correct it quickly ? Is it possible to turn on the logging of Javascript errors into file in the similar way like in case of PHP or SQL errors ?
give a positive ratinggive a negative rating
20 Nov 2021 at 06:06 PM

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.
give a positive ratinggive a negative rating
21 Nov 2021 at 07:12 PM
Share on FacebookShare on TwitterShare on LinkedInSend email
2023 AnswerTabsTermsContact us
How would you rate your experience with AnswerTabs ?
Very badVery good
Thank you for your feedback.