Usage of prompt
suggest changeprompt is a browser method. It displays a dialog requesting input. You can provide a message that will be placed above the text field. The return value is a string, or null if the user cancels. An empty field returns "".
const name = prompt("What's your name?");
console.log("Hello, " + name);
You can also pass prompt() a second parameter, which will be displayed as the default text in the prompt’s text field.
const name = prompt('What\'s your name?', ' Name...');
console.log('Hello, ' + name);
| Parameter | Description |
|---|---|
| message | Required. Text to display above the text field of the prompt. |
| default | Optional. Default text to display in the text field when the prompt is displayed. |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents