<< Chapter < Page Chapter >> Page >

Two sides to every function

There are two sides to the use of every function:

  1. The function definition.
  2. The function call.

The definition names the function and specifies how it will behave when it is called.

The call to the function temporarily passes control to the statements in the function causing them to behave as previously defined.

Once the statements have been executed, control is returned to the point in the script where the call was made. The function may, or may not return a valuewhen it returns control.

The argument list

As in the sphere example discussed above, it is often useful to pass information to the function for it to use in doing whatever it is supposed to do(but this is not always required). When we call the function, we include parameters in the call to the function that match up with the argument listmentioned above. That is the mechanism used to pass information to a function. (This will probably make more sense when you see an example. Again, in somecases, no arguments are required.)

The purpose of a function

Usually (but not always), the purpose of a function is to calculate or otherwise determine some value and return it. In the sphere example mentionedearlier, the purpose of the function would be to calculate and return the surface area of the sphere. Returning a value is accomplished using the return keyword in the body of the function.

Sometimes, the purpose of a function is not to return a value, but instead to cause some action to occur, such as displaying information in the browserwindow. In that case, a return statement is not required. However, it doesn't cause any problem to put a return statement at the end of the function's body with nothing to the right of the word return.

An example function named getHalf

The code in Listing 2 defines a function named getHalf and then calls that function from two different locations in a script, passing adifferent parameter value with each call.

Listing 2 . An example function named getHalf.
<!-- File JavaScript02.html --><html><body><script language="JavaScript1.3">//This is the syntax for a comment. //Define the function named getHalf()function getHalf(incomingParameter) { return incomingParameter/2;}//end function getHalf() document.write("Call getHalf for 10.6","</br>") document.write("Half is: ", getHalf(10.6),"</br>"); document.write("Call getHalf again for 12.3","</br>") document.write("Half is: ", getHalf(12.3));</script></body></html>

A note about comments

Note the line of code immediately following the first script tag that begins with //. Whenever JavaScript code contains such a pair of slashmarks (that are not inside of a quoted string), everything from that point to the end of the line is treated as a comment. A comment is intended for human consumptiononly and is completely ignored when the script is run.

The function definition

The function definition in Listing 1 consists of the three lines of code following the comment that begins with "//Define the function..."

As explained earlier, this function definition contains:

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask