Print Strings with alert() method

We can provide strings in pop up dialogue box. It can be shown using any of the alert, prompt or confirm method.

Example: The below code implements alert box to print the string in dialog box.

HTML
<!DOCTYPE html>
<html>

<body>
    <h2>Hello,w3wiki</h2>
</body>
<script>
    alert("Hello Geeks!");
</script>

</html>

Output:

Alert message


How to Print a String in JavaScript ?

In JavaScript, printing a string means displaying the contents of a string variable or literal to the console, webpage, or any other output medium. Strings are a fundamental data type in JavaScript, representing sequences of characters enclosed within single (”) or double (“”) quotes.

Table of Content

  • Print Strings on Console
  • Print Strings on webpage
  • Print Strings with alert() method

Similar Reads

Print Strings on Console

It is commonly used for debugging and logging messages to the browser console. You can check the printed string by going to the inspect element and then selecting the console tab....

Print Strings on webpage

We can use either the document.write() method or the innerHTML property to print the string on web page....

Print Strings with alert() method

We can provide strings in pop up dialogue box. It can be shown using any of the alert, prompt or confirm method....