Javascript – Why does accessing 'window.variable' return 'undefined' when using 'let' but not with 'var'?
Consider the following code snippets: // Using var var val = 20; console.log(window.val); // Outputs: 20 // Using let let val = 20; console.log(window.val); // Outputs: undefined In both cases, val is declared in the global scope, yet accessing window.val…