0

I'm not well familiar with JS, as I mostly develop desktop applications. But I do know how to use Firebug ;) I'm wondering how can I find the sequence those much *.js files loaded with HTML being executed and where it starts from? I have no clue how javascript code works.. And I need your tips on it.

I just would like to debug one website page and see how it works (like I do it in MS Studio by stepping into code which everytime starts from the same entry point).

Where do javacript code starts?

I'm sorry if my question sounds foolish..

Jeffrey Rasmussen
  • 367
  • 4
  • 8
  • 21
  • 1
    Here are some useful posts: [http://stackoverflow.com/questions/1795438/load-and-execution-sequence-of-a-web-page](http://stackoverflow.com/questions/1795438/load-and-execution-sequence-of-a-web-page), [http://stackoverflow.com/questions/3887408/javascript-function-declaration-and-evaluation-order](http://stackoverflow.com/questions/3887408/javascript-function-declaration-and-evaluation-order) – cbayram Nov 08 '12 at 08:05

4 Answers4

2

Javascript starts at the top of the file. Everything gets executed from top to bottom and there is no such 'start method' you see in codes like (OO) Java or other desktop languages.

You can see it as a procedural language in this case. You can do Object Oriented-like things in Javascript though.

Martin
  • 1,488
  • 1
  • 13
  • 16
1

Scripts are loaded and interpreted in the order in which you inserted them into the markup. You can set breakpoints in Firebug by going to "Scripts" and you should see the breakpoints on the left panel (you may have to reload the page). Breakpoints can also be created in your actual code by just typing debugger; and when you run it in the browser it'll stop execution on that line.

elclanrs
  • 92,861
  • 21
  • 134
  • 171
1

JavaScript code starts and executes in the order it appears in the page.

If you have script tags to include external JS files, the code in these files will be run sequentially in the order they appear in the file.

For example let's say we have the following:

<script type="text/javascript" src="file1.js" />
<script type="text/javascript">
    alert(2);
</script>
<script type="text/javascript" src="file2.js" />

Let's say file1.js contains alert(1); and file2.js contains alert(3);.

You would receive 3 alerts in the following order: '1', '2', '3'.

You could debug this by either putting debug; in any of the 3 files (and turning debugging on in Firebug) or by using Firebug to place breakpoints in any of the 3 files (using the dropdown file selector).

Mitch Satchwell
  • 4,770
  • 2
  • 24
  • 31
0

Firebug is an add on. It can show you source code, response etc. Html, CSS, Javascript, Ajax, Cookies and many things. You can also debug javascript here. But first you need to install this add on. Go to tools option on your browser and install this "firebug" add-on. You can find it by searching.
Here you can debug script part like visual studio. But you cannot debug source code because it's been run on the server.
But as javascript is a client side code.After installing
1. Right click on mouse. choose install with firebug
2. Choose script tab.
3. Set debugger like VS.
4. Debug.

polin
  • 2,745
  • 2
  • 15
  • 20