Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | Output

  • Difficulty Level : Basic
  • Last Updated : 28 Mar, 2019

JavaScript Output defines the ways to display the output of a given code. The output can be display by using four different ways which are listed below:

  • innerHTML: It is used to access an element. It defines the HTML content.

    Syntax:

    Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

    document.getElementById(id)

    Example: This example uses innerHTML to display the data.




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            JavaScript Output using innerHTML
        </title>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
      
        <h2>
            JavaScript Display Possibilities
            Using innerHTML
        </h2>
      
        <p id="GFG"></p>
          
        <!-- Script to uses innerHTML -->
        <script>
            document.getElementById("GFG").innerHTML
                    = 10 * 2;
        </script>
    </body>
      
    </html>                    

    Output:

  • document.write(): It is used for testing purpose.

    Syntax:



    document.write()

    Example: This example uses document.write() property to display data.




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            JavaScript Output using document.write()
        </title>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
      
        <h2>
            JavaScript Display Possibilities
            Using document.write()
        </h2>
      
        <p id="GFG"></p>
          
        <!-- Script to uses document.write() -->
        <script>
            document.write(10 * 2);
        </script>
    </body>
      
    </html>                    

    Output:

  • window.alert():It displays the content using an alert box.

    Syntax:

    window.alert()

    Example: This example uses window.alert() property to display data.




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            JavaScript Output using window.alert()
        </title>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
      
        <h2>
            JavaScript Display Possibilities
            Using window.alert()
        </h2>
      
        <p id="GFG"></p>
      
        <!-- Script to use window.alert() -->
        <script>
            window.alert(10 * 2);
        </script>
    </body>
      
    </html>                    

    Output:

  • console.log(): It is used for debugging purposes.

    Syntax:

    console.log()

    Example: This example uses console.log() property to display data.




    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            JavaScript Output using innerHTML
        </title>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
      
        <h2>
            JavaScript Display Possibilities
            Using console.log()
        </h2>
      
        <p id="GFG"></p>
          
        <!-- Script to use console.log() -->
        <script>
            console.log(10*2);
        </script>
    </body>
      
    </html>                    

    Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!