{"version":"1.0","type":"rich","title":"settimeout-iif.js","description":"This example demonstrates how JavaScript’s closure scope preserves loop variable values inside asynchronous callbacks. The code defines a `tellMeLater` function that iterates ten times, each iteration wrapping a `setTimeout` call in an immediately-invoked function expression (IIFE). By passing `i` as an argument to the IIFE, each timeout callback logs its own unique index (0 through 9) after a 100-millisecond delay, avoiding the classic loop-variable capture problem. The example uses no external libraries, relying solely on native JavaScript `setTimeout` and `console.log` to show the expected sequential output.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-203526d1e4e34eaf4c7e?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}