Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confused about Javascript Function Declaration

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
WHy did you repost? https://coderanch.com/t/488209/HTML-JavaScript/Javascript-Variable-scope

If you did not understand it so so there.

Eric
 
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic