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">

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.


Our First JavaScript Programming

Let’s write our first JavaScript Program.

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

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.


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.
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


Interesting BlogPosts to read

How to Flatten a 2-D array in JavaScript ?
You can flatten a 2-D array in JavaScript using the concat and apply method as shown in the below co...
How to convert from Degree to Radian in JavaScript ?
Assume that you have an angle in degree and you wish to convert it to radians in JavaScript so that ...
How to Prevent your App from being Installed on Windows Phone that does not match the requirements ?
There are times when you want to prevent your app from being downloaded and installed on the Windows...