Use console.log() statements:
Using console.log() commands to print out values and variables as your code runs is the simplest technique to debug your code. This can assist you in locating the bug in your code and determining what variables might be to blame.
The majority of contemporary browsers have an integrated debugger that enables you to set breakpoints in your code. The debugger will pause execution when your code encounters a breakpoint, allowing you to inspect variables and step through your code line by line. This can be especially helpful when debugging challenging problems.
Use a linter:
Linters are programmes that check your code for any errors and infractions of coding conventions. A linter, such as ESLint or JSLint, can find many issues before they even appear.
Write unit tests:
You may find defects early in the development process and make sure that your code is functioning as intended by creating unit tests. You can find faults before they develop into more complicated problems by testing each function or module separately.
Use browser extensions: