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)
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🧠 Test Your Knowledge

2 Questions

Progress: 0 / 2
Keep Going!JS - Functions