Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

Confused about Javascript Function Declaration

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Report post to moderator
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?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic