window[name] equivalent to dynamically access const and let declarations
The old style JavaScript var declaration outside of a closure is global (top-level scope) and can be accessed in a browser from the window object. For example, the declaration var x = 3; can be accessed with window['x'] . How do you similarly access a const or let declaration given the name (string) of the declaration? var x = 3; const y = 7; let z = 21; console.log('x = ' + window['x']); //x = 3 console.log('y = ' + window['y']); //y = undefined console.log('z = ' + window['z']); //z = undefined For the above example, how do you get the values 7 and 21 for "y" and "z" instead of undefined ?