JAVASCRIPT OUTPUT

 

JavaScript can "display" data in different ways they are:

  1. innerHTML.
  2. document.write().
  3. window.alert() and
  4. console.log().
USING innerHTML:

writing into an HTML element using innerHTML, to access javascript we can use the 
 
documet.getElementByid('id name') method.

EXAMPLE:

<html>

<head>

</head>>

<script>

    document.getElementById('hello').innerHTML='HELLO JAVA SCRIPT';

</script>

<body>

    <p> This is my first java script program. </p>

    <p id="hello">HELLO JAVA SCRIPT </P>

</body>

</html>


Output

This is my java script program. 

HELLO JAVA SCRIPT


USING document.write( ):

writing into the HTML output using document.write()

For testing purpose, we can use document.write()

<html>

    <head>

    </head>>

    <script>

        function dw( ) {

        document.write(5+6);

        }

    </script>

    <body>

        <p> This is my first script program. </p>

        <button onclick="dw(m )">click</button>

    </body>

</html>

Output

This is my java script program. 

click


USING window.alert( ):

Writing into an alert box using window.alert().

<html>

    <head>

    </head>>

    <script>

        window.alert('Warning');

    </script>

    <body>

        <p> This is my java script program. </p>

    </body>

</html>

USING console.log( ):

For debugging purpose, we can use console.log method. 

<html>

    <head>

    </head>>

    <script>

        console.log (5+2);

    </script>

    <body>

        <p> This is my java script program. </p>

    </body>

</html>

Output

This is my java script program. 

JAVA SCRIPT PRINT:

Java Script is used to print the page.

<!DOCTYPE html>

<html>

    <head>

    </head>

    <body>

        <p>Click the button to print the page.</p>

        <button onclick="window.print()">Prin</buttont>

    </body>

</html>