Home

JavaScript is a object-based scripting language. It is light weighted. Using HTML we can only design a web page but you can not run any logic on web browser like addition of two numbers, check any condition, looping statements (for, while), decision making statement (if-else) at client side. All these are not possible using HTML So for perform all these task at client side you need to use JavaScript.

Born JavaScript

It is first implemented by Netscape (with help from Sun Microsystems). Javascript was created by Brendan Eich at Netscape in 1995 for the purpose of allowing code in webpages

Prerequisites

Before learning of JavaScript you must be basic knowledge of C Language (mainly looping and conditional statements concept), and also knowledge of Html. Knowledge of looping and conditional statements concept in C language is required because JavaScript is used for perform logical operation of client side.

Introduction

JavaScript is a object-based scripting language and it is light weighted. It is first implemented by Netscape (with help from Sun Microsystems). JavaScript was created by Brendan Eich at Netscape in 1995 for the purpose of allowing code in web-pages (performing logical operation on client side).
It is not compiled but translated. JavaScript Translator is responsible to translate the JavaScript code which is embedded in browser.
Netscape first introduced a JavaScript interpreter in Navigator 2. The interpreter was an extra software component in the browser that was capable of interpreting JavaSript source code inside an HTML document. This means that web page developer no need other software other than a text editor of develop any web page.

Why we Use JavaScript?

Using HTML we can only design a web page but you can not run any logic on web browser like addition of two numbers, check any condition, looping statements (for, while), decision making statement (if-else) at client side. All these are not possible using HTML So for perform all these task at client side you need to use JavaScript.

Where it is used?

It is used to create interactive websites. It is mainly used for:
  • Client-side validation
  • Dynamic drop-down menus
  • Displaying data and time
  • Build small but complete client side programs .
  • Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and prompt dialog box)
  • Displaying clocks etc.

History

JavaScript is a object-based scripting language and it is light weighted. It is first implemented by Netscape (with help from Sun Microsystems). JavaScript was created by Brendan Eich at Netscape in 1995 for the purpose of allowing code in web-pages (performing logical operation on client side).
Using HTML we can only design a web page but you can not run any logic on web browser like addition of two numbers, check any condition, looping statements(for, while), decision making statement(if-else) etc. All these are not possible using HTML so for perform all these task we use JavaScript.
Using HTML we can only design a web page if we want to run any programs like c programming we use JavaScript. Suppose we want to print sum of two number then we use JavaScript for coding.

Features of JavaScript

JavaScript is a client side technology, it is mainly used for gives client side validation, but it have lot of features which are given below:
  • JavaScript is a object-based scripting language.
  • Giving the user more control over the browser.
  • It Handling dates and time.
  • It Detecting the user's browser and OS,
  • It is light weighted.
  • JavaScript is a scripting language and it is not java.
  • JavaScript is interpreter based scripting language.
  • JavaScript is case sensitive.
  • JavaScript is object based language as it provides predefined objects.
  • Every statement in javascript must be terminated with semicolon (;).
  • Most of the javascript control statements syntax is same as syntax of control statements in C language.
  • An important part of JavaScript is the ability to create new functions within scripts. Declare a function in JavaScript using function keyword.

Uses of JavaScript

There are too many web applications running on the web that are using JavaScript technology like gmail, facebook,twitter, google map, youtube etc.

Uses of JavaScript

  • Client-side validation
  • Dynamic drop-down menus
  • Displaying data and time
  • Validate user input in an HTML form before sending the data to a server.
  • Build forms that respond to user input without accessing a server.
  • Change the appearance of HTML documents and dynamically write HTML into separate Windows.
  • Open and close new windows or frames.
  • Manipulate HTML "layers" including hiding, moving, and allowing the user to drag them around a browser window.
  • Build small but complete client side programs .
  • Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and prompt dialog box)
  • Displaying clocks etc.

Comments

Comment is nothing but it is a statement which is not display on browser window. it is useful to understand the which code is written for what purpose.
Comments are useful in every programming language to deliver message. It is used to add information about the code, warnings or suggestions so that the end user or other developer can easily interpret the code.

Types of JavaScript Comments

There are two types of comments are in JavaScript
  • Single-line Comment
  • Multi-line Comment

Single-line Comment

It is represented by double forward slashes (//). It can be used before any statement.

Example

<script>  
// It is single line comment  
document.write("Hello Javascript");  
</script>  

Result

Hello Javascript

Multi-line Comment

It can be used to add single as well as multi line comments.
It is represented by forward slash (/) with asterisk (*) then asterisk with forward slash.

Example

<script>  
/* It is multi line comment.  
It will not be displayed */  
document.write("Javascript multiline comment");  
</script>  

Result

Javascript multiline comment

First Program

Javascript simple example to verify age of any person, if age is greater than 18 show message adult otherwise show under 18

JavaScript Example to verify age

Example

<html>
<head>
<script>
function verify(){
var no;
no=Number(document.getElementById("age").value);
if(no<18)
{
alert("Under 18");
}
else
{
alert("You are Adult");
}
}
</script>
</head>
<body>
Enter your age:<input id="age"><br />
<button onclick="verify()">Click me</button>
</body>
</html>

Result

Enter your age: