معضل شمارش معکوس
بازگشت به صفحه اصلی
بازگشت به صفحه مقاله
دو ستونی
دو سطری
اجرای کد RUN »
<!DOCTYPE html> <html> <body> <h2>JavaScript Function Closures</h2> <p>Counting with a global variable.</p> <p id="demo"></p> <script> // Initiate counter var counter = 0; // Function to increment counter function add() { counter += 1; } // Call add() 3 times add(); add(); add(); // The counter should now be 3 document.getElementById("demo").innerHTML = "The counter is: " + counter; </script> </body> </html>