prompt("What is your name?");
After you press Return or Enter, a pop‐up window appears in your browser window with a text field, as shown here.
After you enter your name and click OK, the pop‐up window disappears, and the value that you entered in the pop‐up displays in the console, as shown here.
That’s all well and good if all you want to do is capture data and immediately repeat it back like a parrot. But what if you want to do something with the user‐entered data? To do that, you need to store it in a variable.
To store user‐entered data in a variable, you create a new variable and then follow it with =. You then follow it with the prompt statement.
var username = prompt("What is your name?");
When you press Return or Enter, a pop‐up window appears in your browser, just as before.