console.log(); vs window.alert();

console.log(); vs window.alert();

console.log()

All modern web browsers, Node.js, as well as almost every other JavaScript environment, support writing messages to a console using a suite of logging methods. The most common of these methods is console.log().

In a browser environment, the console.log() function is predominantly used for debugging purposes. To get started open up the JavaScript Console in your browser, type the following, and press enter.

console.log("Hello, World!");
No alt text provided for this image

In the example above, the console.log() function prints Hello, World! to the console and returns undefined (shown above in the console output window). This is because console.log() has no explicit return value.

window.alert()

The alert method displays a visual alert box on screen. The alert method parameter is displayed to the user in plain text:

window.alert(message);

Because window is the global object, you can call also use the following shorthand:

alert(message);

So what does window.alert() do? Well, let's take the following example:

alert('hello, world');

However, the specification actually allows other event-triggered code to continue to execute even though a modal dialog is still being shown. In such implementations, it is possible for other code to run while the modal dialog is being shown.

The use of alerts is usually discouraged in favor of other methods that do not block users from interacting with the page - in order to create a better user experience. Nevertheless, it can be useful for debugging.

In Chrome 46.0, window.alert() is blocked inside an <iframe> unless its sandbox attribute has the value allow-modal.

Unlike using console.log , alert acts as a modal prompt meaning that the code calling alert will pause until the prompt is answered. Traditionally this means that no other JavaScript code will execute until the alert is dismissed

And its DRAW all win because console.log and window.alert are used in their respective or purpose.

Enjoy code, Enjoy Life </>

To view or add a comment, sign in

More articles by Atul Bhalerao

  • Stop iframe video playback - YouTube using jQuery

    Hi All In day to day life most of the frontend develop are always fighting to stop video which is in the modal popup…

  • Bootstrap 5 Navigation Menu Solutions

    The was one of the major issue for mega menu development which is been resolved not have a look Looking for old…

  • Remote debug Android devices

    Remote debug live content on an Android device from your Windows, Mac, or Linux computer. This tutorial teaches you how…

  • How to cast Android screen in Ubuntu

    - For designers and developers only Prerequisites An Android device with at least a 5.0 version It is necessary to…

    4 Comments
  • Variable in CSS, seriously?

    When it comes to style guide from designer, we need sass/scss or less to write it, but here we can do it as we did…

  • Get rid of 404 page not found Page

    If you have a domain name but no space, which shows up with 404 PAGE NOT FOUND - Then what is the solution Here is the…

  • How can I modify or disable the HUD's use of the Alt key?

    Yes this is what I want, The HUD is really annoying. Here are the steps for the same.

  • Change the order of DIV (Structure) using CSS flex

    We have many things to do as a frontend developer but the very hated part is to change the structure of the HTML with…

    1 Comment
  • On Click Loader using CSS and Js

    When we think about the request and the response on clicking the button it looks pretty simple but to show the user the…

  • How to use calc in CSS

    Summary: People who know and don't know about it, CSS calc() is used for simple calculations to regulate CSS property…

    1 Comment

Others also viewed

Explore content categories