जावास्क्रिप्ट 1.2 में फंक्शन डेफिनिशन्स को अन्य फंक्शन्स के अंदर नेस्ट किया जा सकता है। हालांकि, एक प्रतिबंध है कि फंक्शन डेफिनिशन्स लूप्स या कंडीशनल्स के अंदर नहीं आ सकते। ये प्रतिबंध केवल फंक्शन स्टेटमेंट के साथ फंक्शन डिक्लेरेशन्स पर लागू होते हैं।
उदाहरण
निम्नलिखित कोड को चलाकर जावास्क्रिप्ट नेस्टेड फंक्शन्स को लागू करना सीखें:
<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>