Your full service technology partner! 
-Collapse +Expand
Search JavaScript Group:

-Collapse +Expand JavaScript Store

Prestwood eMagazine

March Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...JavaScript a...Language Ref...   Print This     
  From the December 2015 Issue of Prestwood eMag
JavaScript Language Reference:
JavaScript Custom Routines (function)
Posted 15 years ago on 11/16/2008 and updated 12/30/2008
JavaScript Code Snippet:
 A flashcard from our JavaScript Flashcards Library
 A code snippet from our JavaScript Code Snippets Page


Languages Focus: Custom Routines

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

JavaScript Custom Routines

JavaScript uses functions and loosely typed parameters. Function definitions must come before their usage so the usual preference when adding JavaScript to HTML pages is to include them between the head tags.

Syntax Example:
function SayHello(pName) {
 document.write("Hello " + pName + "<br>");
function add(p1, p2) {
 var result;
 result = p1 + p2;
 return result;

Complete Example

Here is a complete example of using JavaScript functions in an HTML page. Many developers prefer to put JavaScript functions in the page header as demonstrated here.

<title>JavaScript Coding</title>
<script language="JavaScript"> 
function SayHello(pName) {
 document.write("Hello " + pName + "<br>");
function add(p1, p2) {
 var result;
 result = p1 + p2;
 return result;
<h1>JavaScript Custom Routines</h1>
<script language="JavaScript"> 
document.write("2+2=" + add(2,2));

More Info


Share a thought or comment...
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1257A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101633 Counter
Since 11/16/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2023 Prestwood IT Solutions.   [Security & Privacy]