I am writing JavaScript functions for a web app and I want to test them with different values. How can I test JavaScript functions outside of my web application?
I have Visual Studio 2010 and created a new JavaScript file with the function, how can I debug just that file?
Any help is much appreciated
2 Answers 2
in chrome, hit F12 to open the developer tools. Then navigate to the "Console" tab. you can paste the contents of your javascript file at the prompt and press enter to run it.
note: shift+enter is newline. enter executes your code.
i pasted this in for example:
function test(arg) {
return 'hello ' + arg;
}
test('world');
enter image description here
then pressed enter:
enter image description here
If you want to use Internet Explorer, open up a new tab and go to any page (google, anything as long as it's not blank). Then hit F12 to access the developer tools. From there go to the "Script" tab. Under the script tab, on the top-right press the "Console" button. At the bottom of the console panel you can paste in your script and press "Run script" to execute it.
enter image description here
4 Comments
depends on what browser you are using.
To debug javascript you have to run your application in the browser. In Chrome, Firefox and the latest Internet explorer you can press F12 to open a javascript debugging console. You can execute javascript functions, place breakpoints and much more