Creating a JavaScript script block

JavaScript is a client-side and dynamic scripting language. JavaScript allows you to build interactivity into otherwise static HTML pages. To turn your static HTML page into a dynamic page, you can use the JavaScript code in your web page. To insert JavaScript code in your page, use the script tags almost anywhere inside your HTML page:

<script language="JavaScript">
JavaScript code

Make sure you close your <script> tag, after your JavaScript code, with the closing </script> tag. The <script> tag takes one important attribute: language, which specifies what scripting language you are using. Typically, its values is set to JavaScript.

To create a simple HTML document with a JavaScript script block, write the following code:

<script language="javascript">
document.write ("Learn JavaScript by examples.");

The document.write () is a JavaScript method that is used to display text on a webpage. Simply enclose the text that you want to display on a web page with single or double quotation marks. The following shows the output of the above JavaScript code: