# javascript - duplicate functions



## DJ_Dance (Jul 23, 2005)

Hi,

Just wondering what would occur in the following scenario; say I have two javascript functions which have the same name. Now one is declared in the <head> region of the HTML code enclosed within the <script></script> tags. The other is within a javascript file that is "included" using the 'src' attribute of the script tag. Refer to example below.


```
<html>
         <head>
                   <script type="text/javascript" src="first_file.js">
                   // Same function also declared within first_file.js
                   function foo()
                   {
                         ...
                   }
                   </script>
         </head>
</html>
```
Now assume that the function is called with the following tag:


```
<body onLoad="foo()">
```
Which version of foo is actually executed? I tried it out and found that the version within the javascript file 'first_file.js' is the one that is actually called. However why is this the case? Is it b/c the content of first_file.js gets loaded last, or b/c the functions declared within the file have precedence??

Thanks.


----------



## DumberDrummer (Oct 27, 2003)

Seems to me that it would be because the first_file.js is loaded last, so its still in the Java engine's memory, wiping out the one that was in there before.


----------

