JavaScript Tutorial #2 – Syntax of JavaScript

The JavaScript elements and statements are placed within the script tag within the HTML page.

You can specify the language and the type to the attributes of the script tag.

<script language="javascript" type="text/javascript">
  
</script>

The language attribute specifies what scripting language you are using. This value will be javascript . Note that this attribute is superceded by the type attribute . Know more about language attribute here .

The type attribute is used to indicate the scripting language.

image

Our First JavaScript Programming

Let’s write our first JavaScript Program.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Ginktage.com Home Page</title>
    <script language="javascript" type="text/javascript">
        document.write('Welcome to Ginktage.com JavaScript Tutorial');
    </script>
</head>
<body>
</body>
</html>

The above displays a simple text using the document.write method which is used to write a string to the HTML page. Below is the output of the above HTML code.

image

Other things to know about JavaScript

  • Like other Programming languages like C# , C++ and Java , you end the line with the semicolon in JavaScript . But unlike other languages , the semicolon is optional in JavaScript.
  • JavaScript ignores whitespaces , tabs and line breaks . You can use these in your HTML page to format your program for better readability.
  • JavaScript is a case-sensitive programming language.

Leave A Reply

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

You May Also Like

You might want to filter an array in JavaScript by passing the filter criteria and return the filtered array. In...
You can flatten a 2-D array in JavaScript using the concat and apply method as shown in the below code...
Assume that you have an angle in degree and you wish to convert it to radians in JavaScript so that...