জাভাস্ক্রিপ্ট ১.২ ফাংশন ডিক্লেরেশনকে অন্য ফাংশনের ভিতরে নেস্ট করার অনুমতি দেয়। তবে একটি সীমাবদ্ধতা রয়েছে: ফাংশন ডিক্লেরেশন লুপ বা কন্ডিশনাল ব্লকের ভিতরে থাকতে পারে না। এই সীমাবদ্ধতা শুধুমাত্র function স্টেটমেন্ট ব্যবহার করে ফাংশন ডিক্লেরেশনের ক্ষেত্রে প্রযোজ্য।
উদাহরণ
নিচের কোডটি চালিয়ে জাভাস্ক্রিপ্ট নেস্টেড ফাংশন বাস্তবায়ন শিখুন:
<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>