Display Methods in JavaScript

Display Methods in JavaScript

Interaction Methods:

  • alert - just shows a message,
  • prompt - takes user input and returns input,
  • confirm - shows "OK" and "Cancel" button, returns "true" for "OK" and "false" "Cancel"
const userInput = window.prompt("Please enter your name:", "John Doe");

const confirmDeletion = window.confirm(`Are you sure you want to delete ${userInput}?`);
if (confirmDeletion) {
    alert("Item deleted successfully!");
} else {
    alert("Deletion cancelled.");
}

Display Methods in JavaScript

Interaction Methods:

  • All these methods are modal,
  • they pause script execution and don’t allow the visitor to interact with the rest of the page until the window has been dismissed.