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

Advanced
-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 11 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

KB101633



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.

<html>
<head>
<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;
}
-->
</script>
 
</head>
 
<body>
 
<h1>JavaScript Custom Routines</h1>
<script language="JavaScript"> 
<!--
SayHello("Mike");
document.write("2+2=" + add(2,2));
-->
</script>
 
</body>
</html>

More Info


Comments

0 Comments.
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 = P1226A1
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 play-drums.com 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
10502
Since 11/16/2008
-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


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