This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic

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

Joined: Nov 08, 2001
Posts: 15385
WHy did you repost?

If you did not understand it so so there.

I agree. Here's the link:
subject: Confused about Javascript Function Declaration
It's not a secret anymore!