How To Create An Alert In JavaScript? - Edureka

  1. Blog
  2. How To Create An Alert In Java...
Java/J2EE and SOA (344 Blogs) Become a Certified Professional AWS Global Infrastructure
JavaScript
  • What is JavaScript – All You Need To Know About JavaScript
  • JavaScript Tutorial for Beginners : A Complete Guide
  • What is a JavaScript Variable and How to declare it?
  • What are JavaScript Operators and its Types?
  • What are JavaScript Methods and How to use them?
  • What is indexOf in JavaScript and how does it work?
  • What is a JavaScript Class and how to use it?
  • forEach Loop in JavaScript: One Stop Solution for beginners
  • What are Events in JavaScript and how they are handled?
  • What is Try Catch in JavaScript and how it works?
  • How To Implement JavaScript Trim Method?
  • Java vs JavaScript: What are the differences?
  • What are JavaScript Reserved Words and Keywords?
  • What is the JavaScript MVC Architecture and How does it Work?
  • Top 10 Most Popular JavaScript Frameworks
  • How to Create an Alert in JavaScript?
  • TypeScript vs JavaScript: What are the differences?
  • Important JavaScript Functions You Need to Know About
  • What are the top 20 Javascript String Functions and how to use them?
  • How to submit a form in JavaScript?
  • Removing Elements From An Array In JavaScript
  • How to Build a JavaScript Calculator?
  • How To Best Utilize Onclick In JavaScript?
  • Splice Array in JavaScript: All you need to know Array.Splice() Method
  • How to Implement JavaScript Date Methods?
  • String Concatenation In JavaScript: All you need to know about String concat()
  • Event Bubbling and Event Capturing In JavaScript: All you need to know
  • How to Implement String Length in JavaScript
  • Unshift JavaScript : Know How to Use Unshift() Method in Array
  • What is SetInterval in JavaScript and How Does it Work?
  • Advanced JavaScript Tutorial: The Best Guide to Advanced Aspects
jQuery
  • jQuery Tutorial – A Complete Guide For Beginners
  • Angular Routing: A Complete Guide for Beginners
Interview Questions
  • Top 90+ JavaScript Interview Questions and Answers for 2025
  • JavaScript Projects- Know How to Build Your Own Web Application

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (5 Blogs)
  • Java/J2EE and SOA (341 Blogs)
  • Spring Framework (9 Blogs)
SEE MORE Programming & Frameworks blog posts How to Create an Alert in JavaScript? Last updated on Feb 25,2025 43.4K Views Shareimage not found!WhatsAppimage not found!Linkedinimage not found!Twitterimage not found!Facebookimage not found!Redditimage not found!Copy Link! edureka edureka
  • Bookmark
image not found!image not found!image not found!image not found!image not found!image not found!Copy Link! 16 / 31 Blog from JavaScript Become a Certified Professional

When you open any website, you might see alert pop-ups at times. These JavaScript alert boxes are useful for alerting users to something important. When a JavaScript alert box is triggered, a small box pops up and displays the text that you specify in your JavaScript code. In this article, we will see how the alert in JavaScript works, in the following sequence:

Table of Content
  1. Pop-up Boxes in JavaScript
  2. Alert in JavaScript
  3. How to Create an Alert in JavaScript?

Let’s begin.

Pop-up Boxes in JavaScript

In JavaScript, you can find three kinds of popup boxes:

  • Alert box- An alert box is mostly used to make sure information comes through to the user. When an alert box pops up, you need to click “OK” to proceed.

  • Confirm box- A confirm box is mostly used to verify or accept something for the user. When a confirm box pops up, the user needs to click either “OK” or “Cancel” to proceed. If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

  • Prompt box- A prompt box is used by the user to input a value before entering a page. When a prompt box pops up, the user needs to click either “OK” or “Cancel” to proceed after entering an input value. If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.

These were the different types of popup boxes. So, let’s get into the depth of the alert box and see how you can create an alert box in JavaScript.

Alert in JavaScript

The alert() method in JavaScript displays an alert box with a specified message and an OK button. It is often used to make sure that information comes through to the user.

The alert box takes the focus away from the current window and forces the browser to read the message. So, you should avoid overusing this method, as it prevents the user from accessing other parts of the page until the box is closed.

Syntax:

alert(message)

Here, the message is a string type that specifies the text to display in the alert box, or an object converted into a string and displayed. It is optional.

Example:

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Afunction%20myFunction()%20%7B%0Aalert(%22This%20is%20an%20Alert!%22)%3B%0A%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />

Output:

Alert box - alert in javascript - edureka

How to Create an Alert in JavaScript?

The alert() method in JavaScript displays an alert box. It displays a specified message along with an OK button and is generally used to make sure that the user gets the information. It returns a string which represents the text to display in the alert box. Let’s take an example and see how to create an alert in JavaScript:

<!DOCTYPE html> <html> <head> <title> Alert() Method in JavaScript </title> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0Ah1%20%7B%0Acolor%3A%20Blue%3B%0A%7D%0A%0Ah2%20%7B%0Afont-family%3A%20Impact%3B%0A%7D%0A%0Abody%20%7B%0Atext-align%3A%20center%3B%0A%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;style&gt;" title="&lt;style&gt;" /> </head> <body> <h1>Welcome to Edureka</h1> <h2>Alert in JavaScript</h2> <p> To Display the alert message, click on the "Show Alert Message" button: </p> <button ondblclick="myalert()"> Show Alert Message </button> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Afunction%20myalert()%20%7B%0Aalert(%22This%20is%20the%20Alert%20Message!%22)%3B%0A%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" /> </body> </html>

Output:

After you double click the button, you will get the following output:

Output 2- Alert in JavaScript - edureka

With this, we have come to the end of our article. I hope you understood what is an alert in JavaScript and how you can create an alert box. If you’re just beginning, then watch at this Java Tutorial to Understand the Fundamental Java Concepts.

Check out our Full Stack java Developer Training which comes with instructor-led live training and real-life project experience. This training makes you proficient in skills to work with back-end and front-end web technologies. It includes training on Web Development, jQuery, Angular, NodeJS, ExpressJS, and MongoDB.

Got a question for us? Please mention it in the comments section of “Alert in JavaScript” blog and we will get back to you.

Recommended videos for you

php-and-mysql-server-side-scripting-for-web-development.jpg

PHP and MySQL : Server Side Scripting For Web Development

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft Sharepoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now learn-perl-the-jewel-of-scripting-languages.jpg

Learn Perl-the Jewel of Scripting Languages

Watch Now service-oriented-architecture-with-java.jpg

Service-Oriented Architecture With Java

Watch Now node-js-express-steps-to-create-restful-web-app.jpg

Node JS Express: Steps to Create Restful Web App

Watch Now microsoft-sharepoint-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint-The Ultimate Enterprise Collaboration Platform

Watch Now php-mysql-server-side-scripting-language-for-web-development.jpg

PHP & MySQL : Server-side Scripting Language for Web Development

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now portal-development-and-text-searching-with-hibernate.jpg

Portal Development and Text Searching with Hibernate

Watch Now responsive-web-app-using-cakephp.jpg

Responsive WEB APP using cakePHP

Watch Now building-application-with-ruby-on-rails-framework.jpg

Building Application With Ruby On Rails Framework

Watch Now hibernate-the-ultimate-orm-framework.jpg

Hibernate-the ultimate ORM framework

Watch Now create-restful-web-application-with-node-js-express.jpg

Create Restful Web Application With Node.js Express

Watch Now JAVA-J2EE-WEBINAR-600x3501_-300x175.png

Introduction to JAVA/J2EE & SOA

Watch Now spring-framework-introduction-to-spring-web-mvc-spring-with-bigdata.jpg

Spring Framework : Introduction to Spring Web MVC & Spring with BigData

Watch Now nodejs-communication-and-round-robin-way.jpg

NodeJS – Communication and Round Robin Way

Watch Now implementing-web-services-in-java.jpg

Implementing Web Services In Java

Watch Now rapid-development-with-cakephp.jpg

Rapid Development With CakePHP

Watch Now microsoft-net-framework-an-intellisense-way-of-web-development.jpg

Microsoft .NET Framework : An IntelliSense Way of Web Development

Watch Now effective-persistence-using-orm-with-hibernate.jpg

Effective Persistence Using ORM With Hibernate

Watch Now

Recommended blogs for you

STATIC-BLOCK-IN-JAVA-300x175.jpg

How To Implement Static Block In Java?

Read Article JFrame-in-Java-300x175.png

How to Create JFrame in Java?

Read Article clone-in-java-300x175.jpg

What is Cloning in Java and its Types?

Read Article Feature-Image_4-300x152.jpg

Flask Python: A Comprehensive Guide to Building Web Applications

Read Article Protected-in-Java-300x175.jpg

What is Protected in Java and How to Implement it?

Read Article Javascript-Trim-300x175.jpg

How To Implement JavaScript Trim Method?

Read Article Type-conversion-in-c-300x175.jpg

How To Best Implement Type Conversion In C++?

Read Article What-Is-Full-Stack-Web-Developement-300x152.png

What Is Full Stack Development?

Read Article no-image-1.png

A Complete Roadmap To Learn Data Structures and Algorithms (DSA)

Read Article Priority-Queue-In-Java-300x175.jpg

How To Implement Priority Queue In Java?

Read Article Border-in-CSS-300x175.jpg

How to Implement Different Borders in CSS?

Read Article Access-modifiers-in-Java-300x175.jpg

Access Modifiers in Java: All you need to know

Read Article Runnable-Interface-in-Java-300x175.jpg

What is Runnable Interface in Java and how to implement it?

Read Article no-image-1.png

Understanding Java HashMaps

Read Article loops-in-java-300x175.jpg

A complete Introduction to All the Loops in Java

Read Article no-image-1.png

Application Development vs. Web Development: A Simple Guide

Read Article CSS-INT-blg-300x175.png

Top 50 CSS Interview Questions You Should Prepare For In 2025

Read Article Sort-Function-In-C-300x175.jpg

How To Implement Sort function In C++?

Read Article Java-Programs-300x175.jpg

Basic Java Programs for Practice With Examples

Read Article Bubble-sort-Algorithm-300x175.jpg

How to Implement Bubble Sort in C with Code

Read Article Comments 0 Comments

Join the discussionCancel reply

Trending Courses in Programming & Frameworks

Full Stack Development Internship Program

Full Stack Development Internship Program

  • 29k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (11300) Java Course Online

Java Course Online

  • 82k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 4 (30350) Python Scripting Certification Training

Python Scripting Certification Training

  • 15k Enrolled Learners
  • Weekend
  • Self Paced
Reviews 5 (5850) Flutter App Development Certification Course

Flutter App Development Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4800) Node JS Course with Certification

Node JS Course with Certification

  • 11k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (3850) Data Structures and Algorithms using Java Internship Program

Data Structures and Algorithms using Java Int ...

  • 31k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (12050) Spring Framework Certification Course

Spring Framework Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4950) Advanced Java Certification Training

Advanced Java Certification Training

  • 7k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (2800) Comprehensive Java Course Certification Training

Comprehensive Java Course Certification Train ...

  • 19k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (7250) Microsoft .NET Framework Certification Training

Microsoft .NET Framework Certification Traini ...

  • 6k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (2350)

Browse Categories

Artificial IntelligenceAWSBI and VisualizationBig DataBlockchainBusiness ManagementCloud ComputingCyber SecurityData ScienceData Warehousing and ETLDatabasesDevOpsDigital MarketingEnterpriseFront End Web DevelopmentHuman Resource ManagementInterview QuestionsMobile DevelopmentOperating SystemsOperations ManagementProduct ManagementProject Management and MethodologiesRobotic Process Automationseo interview questionSoftware TestingStrategy and LeadershipSupply Chain ManagementSystems & Architecture webinar REGISTER FOR FREE WEBINAR Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years REGISTER NOW webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

Google Sign up with Google facebook Signup with Facebook

Already have an account? Sign in.

20,00,000 learners love us! Get personalised resources in your inbox.

with Gmail with Facebook

OR

Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

SIGN UP Forgot Password? LOGIN resend ? Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

reset password reset password Send Code imagReshape Your Career! Name* Email ID* Phone Number* Your Total Work Experience* Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years Apply Now

Awesome

We have recieved your contact details.

You will recieve an email from us shortly.

imageMain headingsub heading Click to avail "PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc. image not found! image not found!

How to Create an Alert in JavaScript?

edureka.co

image not found! Whatsapp image not found! Linkedin image not found! Twitter image not found! Facebook image not found! Reddit Copy Link image not found!

Từ khóa » Html Js Alert Button