Reputation: 1
I have a JavaScript file which i want to debug and test, so i want to add some breakpoints to it. now i read that i can do so using Firefox F12 tool. so i did the following steps:-
But I can not find a way to write a custom JavaScript and add breakpoints to it.. is this possible ? or the JavaScript need to be already loaded inside the page to debug it ?
Thanks
Upvotes: 0
Views: 457
Reputation: 6580
One relevant point:
"You can place a debugger;
statement anywhere in your JavaScript code. Once the JS interpreter reaches that line, it will stop the script execution, allowing you to inspect variables and step through your code."
Running a script in your computer
Normally you would have to run an local apache server to do this.
The other option is run the script with node.js. You have plenty of debug options.
Here you got a excelent tutorial about debugging on Node (called Bug Clinic):
https://nodeschool.io/#workshoppers
Upvotes: 1
Reputation: 92314
Just open your console, and use debugger
as one of your statements and the debugger will stop there;
(function(){
var x = 1;
debugger;
console.log(x);
})()
Upvotes: 1