JavaScript 1.2 फ़ंक्शन परिभाषाओं को अन्य फ़ंक्शंस में भी नेस्ट करने की अनुमति देता है। फिर भी, एक प्रतिबंध है कि फ़ंक्शन परिभाषाएं लूप या सशर्त के भीतर प्रकट नहीं हो सकती हैं। फ़ंक्शन परिभाषाओं पर ये प्रतिबंध केवल फ़ंक्शन स्टेटमेंट के साथ फ़ंक्शन घोषणाओं पर लागू होते हैं।
उदाहरण
नेस्टेड कार्यों को कैसे कार्यान्वित किया जाए, यह जानने के लिए आप निम्न उदाहरण को चलाने का प्रयास कर सकते हैं
लाइव डेमो
<html>
<head>
<script>
<!--
functionhypotenuse(a,b) {
functionsquare(x){returnx*x;}
returnMath.sqrt(square(a)+square(b));
}
functionsecondFunction() {
varresult;
result=hypotenuse(1,2);
document.write(result );
}
/-->
</script>
</head>
<body>
<p>Clickthe following button to call the function</p>
<form>
<inputtype="button"onclick="secondFunction()"value="CallFunction">
</form>
</body>
</html>