More
JavaScript can "display" data in different ways :-
1) Using innerHTML
For example -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Tutorial</title>
</head>
<body>
<h4>Here we will write welcome to teknowize using innerHTML</h4>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "welcome to teknowize";
</script>
</body>
</html>
Output
2) Using document.write()
JavaScript can use the document.write() basically for testing purposes.
For example -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Tutorial</title>
</head>
<body>
<h4>Using document.write() for testing purpose</h4>
<script>
document.write(12+30);
</script>
</body>
</html>
Output
JavaScript can use the window.alert() or alert() to display data in a alert box.
For example -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Tutorial</title>
</head>
<body>
<h4>Using window.alert() to show data in alert box</h4>
<script>
alert(12+30);
</script>
</body>
</html>
Output
JavaScript can use the console.log() basically for debugging purposes.
You can see output of console.log() by right click on mouse in web browser then go to console from right box.
For example -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript Tutorial</title>
</head>
<body>
<h4>Using console.log() for debugging purpose</h4>
<script>
console.log(12+30);
</script>
</body>
</html>
Output