Learn JavaScript 02

In first part we discussed about some facts about JS. Let’s go ahead….

Here let’s talk about OUTPUTS in JavaScript.
JavaScript does NOT have any built-in print or display functions. JavaScript can display data in different ways.

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

    Capture 4-alert
    try this code and you can see  an alert box.

  • Writing into the HTML output using document.write().

    Capture 5
    The document.write() method should be used only for testing. Because If we’ll  use document.write() after an HTML document is fully loaded, will delete all existing HTML.
    below example will explain it. Try this code and you can understand what I’ve told above.

    Capture 6

  • Writing into an HTML element, using innerHTML.

    By using document.getElementById(id) method, we can access an HTML element.
    The id attribute defines the HTML element. The innerHTML property defines the HTML content:

    Capture 7.1
    When we click the “click” button, document.getElementById() method runs and It passes the “Ohh this is cool” string to header which id = “ID”.

  • Writing into the browser console, using console.log().

    In browser we can use the console.log() method to display data. For this we have to activate the browser console with F12 and select console in the menue.

    Capture 8
    First run the html file. Then press F12 and you can see a window. then click a console menue and you can see the answer 11.

OK in this part we discussed about OUTPUTS in JavaScript. In the next part
let’s discuss about more things.






2 thoughts on “Learn JavaScript 02

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s