dave
dave

Reputation: 15499

How to find line in javascript that is failing or causing javascript to crash/not continue execution

Ok, im more of backend programmer so i have very little to no experience on the front-end.

I know when javascript execution has failed due to a bug, like when the page doesn't render properly(due to some javascript code) etc, so how do i find the bug in javascript code? I'm using simple notepad++.

Upvotes: 0

Views: 561

Answers (3)

SYNCRo
SYNCRo

Reputation: 470

You can catch errors in Javascript using try-catch. This piece of code work in Chrome, I didn't tested in other browsers.

try {
    undefinedFunction();
} catch(err) {
    alert(err.message + new Error().stack);
}

Upvotes: 0

Matt Urtnowski
Matt Urtnowski

Reputation: 2566

Most browsers have developer tools. Hit F12 and there is a good chance it will pop up. Use the console tab to view error output and use the source tab to add breakpoints and watch variables.

Upvotes: 2

yuanb10
yuanb10

Reputation: 117

I would suggest you: (1)open development view of your web browser and check the console to see if there are warnings/errors which ruined your script; (2)if there is no errors, check your code again and see if there are infinite loops or problems like this; then comment out some seem-bad lines and check the code by using console.log() or alert().

Some good tools are truly helpful like firebug. Tutorials abounds. It takes some getting used to, but it will help a lot when you use properly. http://cs-server.usc.edu:45678/resources/tutorials/firebug-571.pdf Good luck.

Upvotes: 1

Related Questions