What are JavaScript Output Types ?

In the JavaScript outputs we have learned so far, we have learned to write in HTML, or rather innerHTML. Thanks to JavaScript, if we want to create an output to the screen there are other methods.

 

Learning these different methods is among the first lessons we learn from JavaScript. We can print the words, expressions and many other things that we will print on the screen through the output of JavaScript.

 

JavaScript Output Types

If we want to create a JavaScript output, we have learned to create innerHTML in our 2 lessons up to now. In this way, by changing the HTML content, we could display what we wanted to print inside the HTML page. In this lesson, let’s talk about how to print the outputs that we need to print on the screen by repeating through innerHML.

 

Using innerHTML in JavaScript

With JavaScript, if we want to change an HTML content, all we have to do is use the innerHTML property of JavaScript. As you will remember from our previous lessons, it doesn’t matter where you define Script tags to use innerHTML.

<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>

What we wanted to do in the script tags that we have written above is the collection of 5 and 6 numbers in the id part of the HTML, so that we can change the HTML content.

 

Using document.write in JavaScript

If we want to create an output with JavaScript in HTML on a website where we will use JavaScript, we need to use document.write.

<body>
<script>
document.write(5+6);
</script>
<button type="button" onclick="document.write('gokmen')">Dene</button>
</body>

HTML will automatically add the numbers 5 and 6 in the HTML scripts and an 11 number will be displayed. But if you have multiplied the button, all HTML content is changed and if you have it, you write the word “gokmen”.. This way we can now output JavaScript as an innerHTML browser.

 

Using windows.alert  in JavaScript

Now, when you look at it in a way, we will send the output we will show this time thanks to a window from the browser, not within the HTML content. For example, you can count the entry of an ip address into your website, and in this box, it is possible to print a value like your 5th arrival today. But before that, what we need to learn is to convert it into an output value before printing anything else in this code. For this:

<body>
<script>
windows.alert('gokmen efsun');
</script>
</body>

In the example above, when you enter the HTML page that you created this code, a small box will open automatically in the browser and it will say “gokmen efsun” in it. Later in this window.alert command, we will learn to write more commands together.

 

In the examples above, we have finally learned how to create a JavaScript output as a warning box. After that, we are ready to continue on the road by adding new information on them. All you have to do is just look at it as it is in every lesson content and video. Now you can write these sections you are looking at. Let it come easy 😊.

Leave a Reply

Your email address will not be published. Required fields are marked *