Nearby lessons

26 of 40

✍️ JavaScript prompt()

📌 What is JavaScript prompt()?

The prompt() method displays a dialog box that asks the user for input.

Includes a text field and OK/Cancel buttons.

📋 prompt() Basics

AttributeDescription
Syntaxprompt(message, default)
ReturnString input or null
Use CaseGetting user input (e.g., name, age)
Example02
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

2 Questions
Progress: 0 / 2