DEV Community

yash kumat
yash kumat

Posted on

3 JS Interactions

1. alert

shows a message.

alert("Hello");

"JavaScript alert"

2. prompt

shows a message asking the user to input text or null.

var name = prompt("What is your name?");

"JavaScript prompt"

Note: You can add an optional second parameter, the initial value for the input field.

var name = prompt("What is your name?", "John");

"JavaScript prompt with default value"

3. confirm

shows a message and waits for the user to press "OK" or "Cancel". It returns "true" for OK and "false" for Cancel.

var confirmation = confirm("Are you sure?");

"JavaScript confirm"

Top comments (0)