*
The moose likes HTML, CSS and JavaScript and the fly likes Confused about Javascript Function Declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic
Author

Confused about Javascript Function Declaration

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi All,

I have this confusion about creating javascript functions. Hope you could enlighten me out.

Say I created a named function:



So I can call it like this since named functions becomes the property of the global object which is the window object



Now, I have made some experiment to help me understand further.

Say I have this HTML.



test1.js has this code:



test2.js has this code:



Now here is where I got confused, when I run this code in firefox, firebug is telling me that sayHi is undefined.

I thought named functions are created before any code is executed. Also I thought only anonymous functions are created during the parsing of the script.

Can you help me out if I miss some basic concept?


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
WHy did you repost? http://www.coderanch.com/t/488209/HTML-JavaScript/Javascript-Variable-scope

If you did not understand it so so there.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confused about Javascript Function Declaration