Skip to content

Introduction to Javascript

April 20, 2013
1.    Important things we need to start JavaScript?First of all we must familiar with HTML completely, without any knowledge of HTML it is not possible to start learning JavaScript. The JavaScript is the language which we need always to use it inside a HTML document.
2.    What is JavaScript?
JavaScript is the most popular language in the web development field. It can be used to create  produce background effects on a web page, validate forms, menus,  provide interactive calendars, post the current day’s headlines, and track a visitor’s history on your site, etc. among many other things.
3.     History of the JavaScript
Netscape developed JavaScript, and was originally called “LiveScript”. it was designed to develop Web pages more interactive. In the beginning the language it was plagued with some security problems, for which the most part, have been overcome. Netscape changed the name javascript in 1995 as a result of an agreement with Sun, the developer of Java.
4.    Is JavaScript and Java same?
Answer is NO! Java is a compiled language, i.e. put into machine language before it gets to your computer. The programming  in JavaScript is few similar to Java but it is much less restrictive.
For e.g, You can assign any type of value to your variables in javascript. But Java does not. Java is a language that is used by experienced programmers to develop applications. JavaScript can only be used in the web development.
5.    First script in javascript
First we will start with a useless script, but it will be nice to show you something JavaScript can do what.
<html>
    <head>
        <title>My first Script</title>
    </head>
    <body>
        <center>
            <h1>This Is My First Script In Javascript</h1>
            <script language=”JavaScript”>
                var today = new Date();
                document.write(today);
            </script>
        </center>
    </body>
</html>
6.    Why the <script> tags?
The HTML tags are used to analyze JavaScript are <script language=”JavaScript”> and </script>. All arguments between these two tags is interpreted as JavaScript programming code by the browser. Mostly browsers have some version of JavaScript built in.

To make comment in javascript we uses <!–       –> and the double slash ( //) that is used in JavaScript to identify a comment. The result looks like this:

<!–    //–>

Therefore the complete syntax for JavaScript programming is:

<script language=”JavaScript”>
<!– This is my comment

   (The JavaScript code)

//–>
</script>

7.    Where to put JavaScripts in HTML code?
We know that we can put javascript codes between the <body> tag of html code because that is where we have already put our first script there. We can also write JavaScript code in the HEAD tag of HTML code. We will understand when we should put the script code in the Head section and when to use the script code in the Body of the document.
 
9.    Why document.write() is used?
Here the document.write() method is use to print the string date in browser. The document.write() method will be used many times in javascript code we will explain it.
The syntax for the document.write() method is as follows:
  • document.write(“string”);
A string is nothing but it’s a series of characters. We put the characters in double quotes, except when the string is something which is returned the other method (like Date) in given example first.
So if we wanta to write “Welcome to the world of javascript.” using document.write(), the example is:
  • document.write(“Welcome to the world of javascript.”);
If we want to add html tag in this string. This way you can underline your “Welcome to the world of javascript.” by we can write as following.
  • document.write(“<u>Welcome to the world of javascript.</u>”);
Now if we want to use the document.write() method to insert an image in our document then normally we should use the <img> tag of html cod to do this. The example will be as if you were inserting the image of sunset.jpg :-
  • <img src=”sunset.jpg”>
<script language=”JavaScript”>
     <img src=”sunset.jpg”>
</script>
Leave a Comment

Leave a comment