How many type of display possibilities in JavaScript?

0 votes
27 views
Ravi Vishwakarma asked 12 days ago in Web Application by Ravi Vishwakarma

how many type of display possibilities in javascipt and explain example.

1 Answer

1 votes
Ethan Karla answered 11 days ago by Ethan Karla
JavaScript can display data in different way.
1. innerHTML
2. window.document.write()
3. window.alert()
4. console.log()
5. window.print()
Inner HTML
     This property used in change the internal data of html elements.
</head>

<body>
    <p>JS demo</p>
    <p id='id1'></p>
    <script>
        document.getElementById('id1').innerHTML = 'this is body tag occur';
    </script>
</body>
</html>
document.write()
     It’s used for testing purpose, this is write data on the html page.
<!DOCTYPE html>

<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
window.alert()
     This is show an alert box on html page. You can skip the window keyword.
<html>

<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.alert(5 + 6);
</script>
</body>
</html>
console.log()
     This is used for debugging purpose. This data show on browser console.
<html>

<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
console.log(5 + 6);
</script>
</body>
</html>
window.print()
     This is used for print the current web page on paper.
<!DOCTYPE html>

<html>
<body>
<button onclick='window.print()'>Print this page</button>
</body>
</html>