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

JavaScript supports different types of operators that includes Assignment Operator JavaScript supports different types if Assignment Operators like = +=...
Assume that you have an angle in degree and you wish to convert it to radians in JavaScript so that...
JavaScript has the support for both single line and multi line comments like C++ or C#. The single line comment...