জাভাস্ক্রিপ্ট ১.২ ফাংশন ডেফিনিশনকে অন্যান্য ফাংশনের ভিতরে নেস্টেড করার অনুমতি দেয়। তবে একটি রেস্ট্রিকশন আছে যে ফাংশন ডেফিনিশন লুপ বা কন্ডিশনালের ভিতরে আসতে পারবে না। এই রেস্ট্রিকশন শুধু ফাংশন স্টেটমেন্টের সাথে ফাংশন ডিক্লেরেশনের ক্ষেত্রে প্রযোজ্য।
উদাহরণ
নেস্টেড ফাংশন ইমপ্লিমেন্ট করার পদ্ধতি শিখতে নিচের উদাহরণটি রান করার চেষ্টা করুন -
<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>Click the following button to call the function</p>
<form>
<inputtype="button"onclick="secondFunction()"value="CallFunction">
</form>
</body>
</html>