Introduction of JavaScript

We will learn today about the introduction of JavaScript.

What is JavaScript ?

It is an object-based programming language which is used create dynamic pages to the client -side.

It is a light-weight and interpreted programming language.

It is easy to learn because it is used with the HTML.

It is free and cross-platform.

It was first known as LiveScript.

Note:
If you have basic knowledge of HTML and CSS then JavaScript is very easy to lean.

Advantage of JavaScript:

The main advantage of JavaScript are given below:

  • User-Interaction:It increase the user interaction with the web-browser and when click the button or other thing in the web.
  • Set -Validation:We can set validation before sending information/data to the server such username,id etc.
  • Compatible with browser:It main benefits that it compatible with all browser.
  • Immediate response:It reloads the page very quickly.

Disadvantage of JavaScript:

The main disadvantage of JavaScript are given below:

  • Code Visibility:code always visible ,anyone can see.
  • Speed:It is not too fast.
  • Networking Application:It cannot be used with the networking application.

JavaScript Example with Code:

<script>
document.write("Hello,first javascript program");
</script>

Here:

document.write is used to display the message/content on the web browser.

Where JavaScript code can put:

There are the three place where you can put the JavaScript code:

  • Inside the body tag of HTML
  • Inside the head tag of HTML
  • With the help of (.js) file means external JavaScript

1.Inside the body tag of HTML

If you want to put JavaScript code inside the body tag then it is very easy same as simple HTML code:

<html>
<head>
<title>JavaScript code inside the body tag</title>
</head>
<body>
<script type="text/javascript">
document.write("hello first javascript program");
</script>
</body>
</html>

Output:

hello first javascript program
This will show on the body web page

2.Inside the head tag of HTML

In this example ,we show the alert dialog box that code contains inside the head tag.

So first we need to create function showmessage( ).

To call this function we need onclick event hander.

<html>
<head>
<script type="text/javascript">
function showmessage( )
{
alert("Hello placementpreparation.com");
}
<script>
</head>
<body>
<input type="button" onclick="showmessage( )" value="message"/>
</body>
</html>

Output:

When click the button then show message in dialog box
'Hello Hello placementpreparation.com'

3.External javascript means( .js file)

We can create external javascript and it can embedded with the HTML code.

This technique is used to code re-usability.

We can write JavaScript code and the save with .js file.

According to requirement we can call the .js file.

Example:

Lets create the external javascript to show message “Hello placementpreparation.com” in the dialog.

firstprogram.js

function showMessage( )
{
alert("Hello placementpreparation.com");
}

Now the above JavaScript code embed into the HTML code.

<html>
<head>
<title>External javascript program</title>
<script type="text/javascript" scr="firstprogram.js">
</script>
</head>
<body>
<input type="button" onclick="showMessage" value="Click on message"/>
</body>
</html>

Output:

When click the button then show message in dialog box
'Hello placementpreparation.com'

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

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