JavaScript in document.write & alert & console.log

 JavaScript in document.write & alert & console.log

In this article we are goanna to see about Document.write() , alert() and console.log() in JavaScript which is most important when you are going to start your career in JavaScript. Please read and enjoy this article if you want to give any feedback about your experience, we welcome.


document.write();

The write() method writes HTML expressions or JavaScript code to a document.
The write() method is mostly used for testing. If it is used after an HTML document is fully loaded, it will delete all existing HTML.



<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>Inline JavaScript</h1>
<script type=“text/javascript”>
document.write(“Hello world”);
</script>
</body>
</html>

alert();

The alert() method displays an alert box with a specified message and an OK button. An alert box is often used if you want to make sure information comes through to the user.

Note: The alert box takes the focus away from the current window and forces the browser to read the message.

<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>Inline JavaScript</h1>
<script type=“text/javascript”>
alert(“Hello world”);
</script>
</body>
</html>



console.log();

log() method to print to console JavaScript. The JavaScript console log function is mainly used for code debugging as it makes the JavaScript print the output to the console. 

To open the browser console, right-click on the page and select Inspect, and then click Console

<html>
<head>
<title>JavaScript Tutorial</title>
</head>
<body>
<h1>Inline JavaScript</h1>
<script type=“text/javascript”>
console.log(“Hello world”);
</script>
</body>
</html>




Share:

0 comments

Please leave your comments...... Thanks