- Using console.log() method
- Using debugger keyword
Using console.log() method
It is used to generate an error message on the console of the browser, in case of any error in the code.
<!DOCTYPE html> <html> <body> <script> a = 2; b = 5; mul = a * b; console.log(mul); console.log(x); </script> </body> </html>
Using debugger keyword
Using debugger keyword, breakpoint are set in the code itself. In case of any error, the code execution stops at that particular line of code and then can be verified manually.
<!DOCTYPE html> <html> <body> <script> a = 2; b = 5; mul = a * b; debugger; document.write(mul); document.write(x); </script> </body> </html>