JavaScript error! How to fix an error in JavaScript code?

Learn how to fix JavaScript errors using your browser console and more.
We will learn from examples how to deal with js errors and other problems. We will also share our practice of dealing with errors in the comments. What will we learn today?

Visualizing Errors in JavaScript

Examples of fixing errors using the console

How to fix an error without a console

Meet the console!

After talking with my developer friends, I was surprised that they never use browser consoles to deal with errors in the code . Well, if you don’t already use the console to identify and fix errors, I advise you to try it right now.

What does it mean?

Naturally, you first need to understand what exactly this error means. To do this, we will use any online translator to translate the phrase into Russian. What happened was: A JavaScript error occurred in the main process.

Now you can move on to finding a solution. Let's look separately at situations where the message “A javascript error occurred in the main process” appears when starting Discord and Skype.

Correction method for Discord

In this case, there are a number of universal recommendations that should definitely be put into practice:

Program update

Yes, sometimes the status A javascript error occurred in the main process occurs precisely because this product requires an update, but the required process, for some reason, is not activated automatically. If this is so, then the user will have to do everything himself:

  • Exit the program, go to the task manager, view the list of running processes, disable those that are guaranteed to be associated with Discord;

  • On the keyboard, simultaneously hold down the “Win” and “R” buttons. The “Run” line will open. Use the %AppData% command in it. And don’t forget to click on OK or Enter to confirm;

  • In the directory tree that opens in this way, you must first return from the “Roaming” folder to “AppData”. Then open the “Local” folder, and in it – the folder with the same name of our program;

  • Among the files you can find “update.exe”. Launch it.

Now you can safely close everything open. Return to the Discord icon. Click on it to start the program. If everything is done correctly, then at this moment the software will begin to perform its update. You need to be patient, wait for the running process to complete, and check the result.

Reinstallation

Didn't the previous option help? Let's move on to the next one. It involves uninstalling the program and installing the current version again. Regular deactivation will not help in this situation. Yes, in this way the user can remove some components, but the remains of the program will still be on the hard drive. And they are the ones who can lead to a recurrence of the problem. Therefore you need to act like this:

  • Naturally, close the program window completely. That is, we get out of it;
  • We launch the task manager again and, just like in the previous situation, gets rid of all programs whose name contains the word “Discord”;
  • Now you need to go to “Programs and Features” through the “Control Panel”;
  • We look through the list and find the product we need. Select it and click on the button to remove the software;
  • Press “VIN” and “R” again. We enter the same command: %AppData%. We confirm it;
  • We make the transition: from Roaming to AppData, then to Local;
  • Find the folder with the name of the program and delete it.

All that remains is to go online. Preferably, to the official website of the developers. Download the installer, run it, and carry out the installation according to the instructions.

What else can you try?

In nine cases out of ten, the methods described above do an excellent job of solving the problem. But there are cases when they don’t help either. What is recommended to try in such situations:

  • Launch a good, up-to-date antivirus program. Diagnose the system and treat it if antivirus software detects any infections. If possible, for greater efficiency, it is advisable to run several antivirus programs sequentially;
  • If the problem began to occur after installing some other program, then you should think about the fact that they are simply incompatible with each other. And uninstalling recently installed software often leads to the discovery of a necessary and effective solution.


SUPERAntiSpyware
Another not-so-pleasant point is that this problem is less common on relatively new operating systems. But on OSs whose support has already been completed by Microsoft, more often. Therefore, if none of the described methods helped get rid of the error, you can only do the following:

  • Completely stop using this program. And try to find an alternative to it;
  • Switch to a more modern operating system. And this is, at a minimum, Windows version eight and higher.

JavaScript Errors

Without diving into the etymology of an error in JavaScript, we will characterize it abstractly, since the error object itself in JS is not completely standardized.

An error in JS is a “throw of an exception”. The exception must be handled by the program, otherwise the interpreter will return us to the place where the exception was thrown. By default, an exception is thrown by an Error object.

It doesn’t matter whether you are writing Frontend or Backend, the approach to handling is the same - catch the unfortunate exception and process it. Everything needs to be processed, especially in production.

Let’s immediately clarify a couple of non-standard situations:

  • Error from outside the program
  • Terminal error

A terminal error is an error code returned by the OS or daemon.

Yandex opens enrollment for summer schools

January 25 – August 31, Online, Free

tproger.ru

Events and courses on tproger.ru

An error from outside the program may be a special case of a terminal error, but nevertheless it must be processed.

Any of these non-standard situations can go into the general error stack and will be processed, because Every thrown exception that enters the program occupies the stack.

We fix it for Skype

Yes, unfortunately the more famous product known as Skype also faces a similar problem. What is proposed to be done:

  1. First of all, install the Skype update to the most current version. And the program sends many users notifications about the need for an upgrade. And, if the settings are set correctly, the next time you start Skype automatically starts the procedure. But for some people, for some reason, this does not happen. And their version is becoming outdated. It needs to be updated manually: go to the official website of the developers, download the current version (naturally, suitable for the system you are using and its bit depth), install the downloaded package.

  2. The next step is to check the version of the Microsoft proprietary browser – Internet Explorer. And updating it to the eleventh version.

Procedure for updating IE to version 11

So, initially we find out the current version of this Internet browser:

  • Launch the browser itself;
  • In the upper right corner we use the button in the form of a gear;
  • The drop-down menu is activated;
  • In it you need to select the “About Internet Explorer” item. Click it and get the required information.

In general, this program itself should be updated automatically. If this does not happen, it is recommended to do the following:

  • Click on the “Start” button at the bottom of the desktop;
  • Go through “Settings” and “Update and Security” to the so-called Windows Update Center;
  • Click on the “check for updates” prompt.

Wait for the running process to complete. If the system detects something, perform the installation.

As an alternative, you can immediately download the eleventh version of this web browser from the official Microsoft website. Naturally, having previously selected the operating system used and its bit depth.

Reset IE settings

You will need to go to this point if the hard drive is guaranteed to have the 11th version of Microsoft's proprietary browser, but the error still continues to appear when launching Skype. If this is the case, then you need to repeat the following operations:

  • Initially, close absolutely all running applications and system windows;
  • Launch IE;
  • Click on the gear icon and select “Internet Options” from the list;
  • In the next window, activate the “Advanced” tab;
  • In it select “reset parameters”. Click on “reset”;
  • Confirm your actions. And after completing the procedure, be sure to restart your personal computer.

Check the result.

Java Setup

It is logical that the Java script should be configured correctly. After all, if you do not do this, then it is quite possible that this particular error will manifest itself. Yes, first of all, you should set the parameters correctly for Internet Explorer. But if the PC owner also uses other browsers, then it’s worth double-checking them too.

Settings for Internet Explorer

The following instructions need to be repeated:

  • Launch your web browser, click on the gear and go to “Internet Options”;
  • Activate the tab called “Security”. Highlight the Internet icon. Click on the “Another level” button;
  • Go to "Scripting". Next in – “Active Scripting”. Set out of three values ​​the one called “Enable”;
  • The system will ask for confirmation. Click on yes. Close a window;
  • Next to the address bar, click the button responsible for refreshing the page.

Setting for Google Chrome

Naturally, Google Chrome is initially activated. Further:

  • Click on the three vertical dots that can be found in the upper right corner of the working screen;
  • A drop-down menu will appear. In it you need to go to the “Settings” section;
  • Scroll down to the very bottom of the page. Click on “Advanced”;
  • Go to “privacy and security”, where you should click on “content settings”.

All that remains is to select “JavaScript” and set the value to connected.

try…catch construction

The try...catch block is the simplest and often overlooked way to handle errors. These days, however, it is used much more intensively than before, due to the fact that it can be used to handle errors in async/await constructs.

This block can be used to handle any errors that occur in synchronous code. Let's look at an example.

If in this example we had not enclosed the failed console.log(b) command in a try...catch block, the script would have stopped running.

Reviews

Reviews will help you figure out what exactly helped other people in a similar situation:

  1. Oleg. By the way, I did the same with Skype as written in the Discord instructions. That is, he completely removed the program, having previously cleared all traces of it that might have been running. And then I installed a new version, as they say, from scratch. And my problem was immediately resolved.
  2. Semyon. At first, I also started to take everything out of the folder. But the system simply did not allow me to do this, saying that the files were, they say, open somewhere else. Then I went, as written in the instructions, to the task manager. I completely deactivated everything. Once again I moved on to deleting. And everything worked out! Next is a matter of technology. Find a normal package, download it and install it.
  3. Valery. Important point. When navigating to folders from which you need to delete something, make sure that they are not in hidden mode. That is, initially you need to set the settings in such a way that all folders on the hard drive are visible to the user. Otherwise, you simply won’t be able to find the elements you need. This means completing the instructions.
  4. Arkady. I tried everything. And here, it turns out, you also need to enable Java in the IE settings. I specifically went to the right section. And I saw that the necessary scripts were in an inactive state. Of course, everything was set up as it should be. And Skype began to function normally. And then this error always popped up, I didn’t even know what to do with it or how to fix it.
  5. Natalia. I had this problem literally a month ago. And I'm not very computer savvy. She called her son. I came and looked. He said that my Skype was very old and just needed to be updated. I installed the normal version. I made it update automatically. Plus, I finally replaced the previously standing XP with the modern Ten. And now I don’t have any problems - I communicate normally with my friends and at work.
Rating
( 1 rating, average 5 out of 5 )
Did you like the article? Share with friends:
Для любых предложений по сайту: [email protected]