0

Say I am creating a function named register(name), and I want to assign a variable in it in the name of the variable name, like I pass:-

 function register(oidu){
var oidu = "idk";
}

and then I pass again:-

 function register(lol){
var lol = "idk";
}

You may observe that the variable is named as the name(value passed in function). I want to do like this in reality. How can I do this?

Pranav
  • 674
  • 1
  • 6
  • 23
  • 6
    Why would you want to do this? It sounds like an [XY problem](https://meta.stackexchange.com/q/66377/398364). – Ivar Sep 15 '19 at 17:28
  • 1
    You can set these variables in the global scope (window object) using bracket notation, i.e. `window['lol'] = 'idk'`. What are you actually trying to do here, though? There isn't really a good use case for this pattern. – Kayla Fuchs Sep 15 '19 at 17:29

0 Answers0