Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

New at javascript and i have some questions?

Yea i've just learn the very basics so i had a few questions

Can I declare multiple functions using the same script tag?

as in (im just giving the basic idea...i know this isnt the correct format)

<script>

Function one { }

Function two { }

</script>

also can i declare variables and functions using an external script

<script src=(my external source to declare)>

2 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Yes, and yes.

  • 1 decade ago

    >Can I declare multiple functions using the same script tag?

    Yes. You can do basically anything you want within a single set of script tags. Well, I guess sooner or later you might hit some data limit specified by your browser, but it is a very high limit indeed. I have personally crammed over 2500 lines of Javascript between a single set of tags, and it worked perfectly.

    >also can i declare variables and functions using an external script

    Yes. And in fact you can include more than one external script at once. However, you have to be careful. If the external script declares a variable or function under the same name and scope as one that already exists from another script, it will likely cause a problem. Also, although functions from either script should be able to access functions and variables in the other one (including, potentially, creating a recursive function that cycles between the two scripts), any 'naked' function calls to be executed on pageload may start running before the other script is fully loaded, which could also cause problems. And if you're putting these files on the Web, you also run a small risk each time you open the main page that the main page will load properly but the JS file won't (for instance, if it is located on a different server that happens to be down, or if it has exceeded its own bandwidth limit, or some such thing), which will cause an error as soon as any script on the main page tries to access variables or functions from the referenced script.

Still have questions? Get your answers by asking now.