This is possible, but you must be careful with context and scope.
1. To set a variable with a global scope in a browser environment:
window[str1 + str2] = value
2. To set a global scope variable in a node environment:
global[str1 + str2] = value
3. Within the closure and within this closure:
this[str1 + str2] = value
Inside the closure, the global and the window will still set global. Please note: if you are in a called function, 'this' may refer to another object.
source share