Skip to main content
100%

Gist 5ef57ecbfb116e6b42706fb6a30b0987

✓ Published0🌍 Public
MMistyBlunch
Last edited Aug 25, 2019
Created on Aug 25, 2019

This example demonstrates a common JavaScript scoping pitfall with the `var` keyword, contrasting it with `let`. It shows that declaring multiple variables in a single statement like `var i, r = 0;` only initializes the last variable (`r`), leaving `i` as `undefined`. Consequently, while loops testing `i < 10` never execute, while loops on `r` run ten times, printing "chau". The visualization, presented as a code gist, uses plain JavaScript console output via `console.log` within `while` loops, relying on the browser's or Node.js runtime rather than any external libraries. The gist highlights the importance of explicit initialization for each variable.

AI-generated description

Similar vizzes