Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Difference Between Scope and Closures in JavaScript
Next article icon

Difference between alert box and prompt box in JavaScript

Last Updated : 19 Apr, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

1. Alert box : An alert box is one type of popup boxes in JavaScript which is often used to make sure that information have come through the user. So, the user will have to click "OK" to proceed when an alert box pops up on the window. 

Syntax :

window.alert("message");

Another syntax to use alert box is :

alert("message");

2. Prompt box : It is also one of the type of popup boxes in JavaScript which is often to take input a value before entering a page from the user. To proceed after entering an input value in the prompt, the user will have to click either "OK" or "Cancel". 

Syntax :

window.prompt("some message");

Another syntax to use alert box is :

prompt("some message");

Below example illustrates the differences between alert box and prompt box : Example : 

HTML
<!DOCTYPE HTML>  <html>   <head>      <title>          Alert Box vs Prompt Box      </title>  </head>   <body style="text-align:center;" id="body">       <h1 style="color:green;">          GeeksforGeeks      </h1>           <button onclick="alertBox()">          Show Alert Box      </button>      <button onclick="promptBox()">          Show Prompt Box      </button>           <script>          function alertBox(){              alert("GeeksforGeeks: This" +                      " is an Alert Box.");          }           function promptBox(){              prompt("Enter your Name:");          }      </script>  </body>   </html>                      

Output: 

Before clicking the button :

  

After clicking the Show Alert Box button :

  

After clicking the Show Prompt Box button : 

 

Supported Browsers: The list of browser supported by prompt() and alert() box are listed below :

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Let us see the differences in a tabular form -:
 

 alert boxprompt box
1.An alert box is used if we want the information comes through to the user.A prompt box is used when we want the user to input a value before entering a page.
2.

Its syntax is -:

window.alert(“sometext”);

Its syntax is -:

window.prompt("sometext","defaultText");

3.It always return true we always need to click on “OK” to proceed further.We need to click "OK" or "Cancel" to proceed after entering an input value when a prompt box pops up on a webpage.
4.The alert box takes the focus away from the current window and forces the browser to read the message.If we click "OK" the box returns the input value.
5.We need to click “OK” to proceed when an alert box pops up.If we click "Cancel" the box returns a null value.

Next Article
Difference Between Scope and Closures in JavaScript

A

aktmishra143
Improve
Article Tags :
  • Difference Between
  • JavaScript
  • Web Technologies

Similar Reads

  • Difference Between alert and console.log in JavaScript
    In JavaScript, alert and console.log are two commonly used methods for the displaying information to the user or the developer. While both the serve the purpose of the outputting data they have different use cases and characteristics. This article explores the differences between the alert and conso
    3 min read
  • Difference between alert box and confirmation box in JavaScript
    In JavaScript, alert and confirm are two built-in functions used to interact with users via dialogue boxes. Both serve different purposes and provide distinct functionalities. Understanding the difference between an alert box and a confirmation box is crucial for effective user interface design and
    3 min read
  • Difference between JavaScript and PHP
    In this article, we will know about Javascript & PHP, along with understanding their significant differences. A long time before, most people used to think PHP is a server-side language and Javascript as client-side language as it was only executed in web browsers. But after V8, Node and other f
    4 min read
  • Difference Between Scope and Closures in JavaScript
    The scope and closures are fundamental concepts that play a crucial role in how variables are accessed and managed within the functions and blocks of code. In this article, we will learn about the difference between scope and closures in JavaScript. What is Scope?The Scope in JavaScript refers to th
    2 min read
  • Difference between var and let in JavaScript
    In the early days of JavaScript, there was only one way of declaring variables and that was using the var keyword. A variable declared with var is defined throughout the program. One of the issues with using the var keyword was redeclaring a variable inside a block will also redeclare the variable o
    3 min read
  • Difference between JavaScript and VBScript
    JavaScript and VBScript are both scripting languages used to automate tasks and enhance web pages. JavaScript is widely supported across all modern browsers and platforms, making it the preferred choice for web development. In contrast, VBScript is primarily used in Internet Explorer and Windows env
    2 min read
  • Difference between JavaScript and JSP
    JavaScript is a lightweight and object-oriented scripting language used to create dynamic HTML pages with interactive effects within a webpage. It is an interpreted scripting language and its code is run in a web browser. It is also called a browser’s language and can be used for client-side develop
    3 min read
  • Difference Between label and break in JavaScript
    The labels and the break statement are used within loops and control flow structures to enhance flexibility and manageability. Each serves distinct purposes and can be applied in the various scenarios based on the needs of the code. These are the following topics that we are going to discuss: Table
    3 min read
  • Difference between addEventListener and onclick in JavaScript
    In JavaScript, both addEventListener() and onclick are used to handle events like clicks, but they function differently. While addEventListener() allows multiple event listeners and better control over event propagation, onclick is limited to a single event handler and gets overwritten. addEventList
    4 min read
  • Difference between JavaScript and HTML
    JavaScriptJavaScript is a programming language that conforms to the ECMAScript specification. It is a high-level scripting language introduced by Netscape to be run on the client-side of the web browser. It can insert dynamic text into HTML. JavaScript is also known as the browser’s language. HTMLHT
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences