JavaScript 1.2 อนุญาตให้ประกาศฟังก์ชันซ้อนกันได้ แต่มีข้อจำกัด: ไม่สามารถประกาศฟังก์ชันภายใน Loop หรือ Conditional ได้ ข้อจำกัดนี้ใช้กับ Function Declaration ที่ใช้คีย์เวิร์ด 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(1,2);
document.write(result );
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="secondFunction()" value="Call Function">
</form>
</body>
</html>