HOLLA TECH - LEARN

Your First JavaScript
 

Let’s start with adding JavaScript to a webpage.
JavaScript on the web lives inside the HTML document.
In HTML, JavaScript code must be inserted between <script> and </script> tags:

<script>
  
</script> 

Result: 

Holla Tech - Learn JavaScript

JavaScript can be placed in the HTML page’s <body> and <head> sections.
In the example below, we placed it within the <body> tag.

NOTE!
Remember that the script, which is placed in the head section, will be executed before theis rendered. If you want to get elements in the body, it’s a good idea to place your script at the end of the body tag.

Output
 

Let’s use JavaScript to print “Hello World” to the browser.

html>
   <head> </head>
   <body>
     <script>
       document.write(“Hello World!”);
     </script>
   </body>
</html>

 

The document.write() function writes a string into our HTML document. This function can be used to write text, HTML, or both.

The above code displays the following result:

Holla Tech - Learn JavaScript

NOTE!
The document.write() method should be used only for testing. Other output mechanisms appear in the upcoming lessons.

Formatting Text
 

Just like in HTML, we can use HTML tags to format text in JavaScript.
For example, we can output the text as a heading. 

<html>
   <head> </head>
   <body>
     <script>
       document.write(<h1>Hello World!</h1>);
     </script>
   </body>
</html

 

Result: 

Holla Tech - Learn JavaScript


BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE JAVASCRIPT MAIN COURSE PAGE. 

JAVASCRIPT MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT