Usage of prompt

suggest change

prompt 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents