
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What are JavaScript Nested Functions?
JavaScript 1.2 allows function definitions to be nested within other functions as well. Still there is a restriction that function definitions may not appear within loops or conditionals. These restrictions on function definitions apply only to function declarations with the function statement.
Example
You can try to run the following code to learn how to implement JavaScript Nested Functions −
<html> <head> <script> function hypotenuse(a, b) { function square(x) { return x*x; } return Math.sqrt(square(a) + square(b)); } function secondFunction(){ var result; result = hypotenuse(3,4); document.write ( result ); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type = "button" onclick = "secondFunction()" value = "Find Hypotenuse"> </form> </body> </html>
- Related Articles
- How to define nested functions in JavaScript?
- What is the difference between closure and nested functions in JavaScript?
- What are JavaScript Math Functions?
- What are functions in JavaScript?
- What are JavaScript Factory Functions?
- What are callback functions in JavaScript?
- What are generator functions in JavaScript?
- What are immediate functions in JavaScript?
- What are Partial functions in JavaScript?
- Nested functions in C
- What are optional arguments in JavaScript Functions?
- What are Rest parameters in JavaScript functions?
- What are Self-Invoking Anonymous Functions in JavaScript?
- What are different ways of defining functions in JavaScript?
- How to append new information and rethrowing errors in nested functions in JavaScript?

Advertisements