How to create a function in JavaScript?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

How to create a function in JavaScript?

Rating:

Functions can be considered as sub-programs that are defined to perform different actions. Functions can be invoked within another function or invoked by an event handler of an object. They are defined by using the function keyword followed by a set of parentheses. A function cannot be created within another function, but it can be called by another function. In JavaScript, functions are defined to perform different actions such as performing calculations, creating objects, referencing objects, etc.

The syntax for declaring a function is as follows:

function myfunc()
{
       //statements
}


The syntax for invoking a function is as follows:

<input type="button" value="Click Me" onclick="myfunc()">


Rating:



Other articles

Click here to Article home

MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW Certification: CIW foundation, CIW Professional, Site Designer    Photoshop ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.