JavaScript prompt() Method

You are Here:

JavaScript prompt() Method

The prompt() method displays a dialog with an optional message prompting the user to input some text.

This method returns the user typed value.


HTML Online Editor
<!DOCTYPE html> <html> <body> <p onclick="myFunction()">Click me</p> <p id="point"></p> <script> function myFunction(){ var ans = prompt("How old are you?", 35); var txt = "You replied: " +ans document.getElementById("point").innerHTML = txt; } </script> </body> </html>


prompt(question, answer)

Parameter Values

questionRequiredA question to display to the user.
answerOptionalSpecifies a default answer.

Return Value

StringReturns the user typed value.


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author