Technical Training
JavaScript TutorialJavaScript Functions
JavaScript Functions
In this JavaScript tutorial, you will learn about JavaScript functions and how to create them.
Ads
What is a function?
Function is a block of code that can be reused as and when needed at various places. The function executes whenever it is called.
JavaScript Functions:
How does a programmer define, create and handle functions in JavaScript?
In JavaScript, the programmer must learn the following broad classifications to fully understand the concept of functions.
- Idea of JavaScript functions
- Creating a function in JavaScript
- Passing values to function
- Returning values from a function
Idea of JavaScript Functions:
As mentioned above, a function is a piece of code that is reusable by the programmer as and when needed. The function executes when it is called and this calling can be done either by an event or by a calling program. Functions in JavaScript are defined at the beginning of the page and are placed in the section. The functions placed in JavaScript can be called from anywhere.
Creating a Function in JavaScript:
General syntax for creating a function in JavaScript is as follows:
|
In the above syntax, argument1, argument2,…argument3 are optional. They are only placed if some values or data needs to be passed to the function. If the function does not have any values to be passed, then the syntax of function in JavaScript would be as follows:
|
Ads
In the above syntax, the first word function represents a keyword, followed by the name of the function and then the block of code which is to be placed within the braces { and }.
JavaScript is case-sensitive, care must be taken to write the keywords with lower case only as specified above.
For example, if a programmer wants to create a function exforsys with no data passed to function it is written in JavaScript as follows:
|
JavaScript Tutorial
- JavaScript Browser Objects Part 2
- JavaScript Frame object
- JavaScript Form Object
- JavaScript FileUpload Object
- JavaScript Event Object Properties and Methods
- JavaScript Event Object
- JavaScript Elements and Embed Objects
- JavaScript Applet Objects
- JavaScript Browser Objects
- JavaScript Object Oriented Features
- JavaScript Window Object Open Method Part 2
- JavaScript Window Object Open Method
- JavaScript Window Object Timeout Methods
- JavaScript Location Object
- JavaScript Location Object Properties
- JavaScript History Object Properties and Methods
- JavaScript Document Object Methods Part II
- JavaScript Document Object Methods Part I
- JavaScript Document Object Properties
- JavaScript Document Object
- JavaScript Windows Object Properties Part II
- JavaScript Windows Object Properties Part I
- JavaScript DOM Window Object
- Working with JavaScript DOM Objects
- JavaScript Array Object Methods – Part II
- JavaScript Array Object
- JavaScript Array Object Methods – Part I
- JavaScript Boolean Object
- JavaScript OnError Event
- JavaScript Exception Handling – Part II
- JavaScript Exception Handling – Part I
- JavaScript Event Handler
- JavaScript Events Handling
- JavaScript Array Operations
- JavaScript Two Dimensional Arrays
- Passing values to JavaScript Function
- JavaScript Functions
- JavaScript Arrays
- JavaScript Iterative Structures - Part II
- JavaScript Iterative Structures - Part I
- JavaScript Math Object
- JavaScript Date Object
- JavaScript String Object
- JavaScript Objects
- JavaScript Confirm Box
- JavaScript Alert Box
- JavaScript Conditional Statements Part 2
- JavaScript Conditional Statements Part 1
- How to use JavaScript in HTML page
- JavaScript Variables
- JavaScript Features
- JavaScript Introduction







