JavaScript (Introduction)

INTRODUCTION

JavaScript created by Brendan Eich at Netscape and was first introduced in December 1995 under the name of LiveScript and after a short while it renamed as "JavaScript" and mostly used to developed dynamic web pages. 

Features of Java Script

1. Scripting Language: JavaScript is an example of scripting language, 

2. Lightweight: Its a lightweight programming language that is interpreted by the web browser (Such: Internet Explorer, Mozilla Firefox, Google Chrome) engine when the web page is loaded.

3. Client side: JavaScript is an example of Client side programming language hence its less secure than compare of server side programming languages such PHP, ASP.NET, etc.  

4. Easily embed-able: Java script code can be  easily embed in any HTML program and entire java script code written in <script> tag.

A simple of example of JavaScript program
<html>
<title> Print simple text by JavaScript function </title>

<|-- Define java script function --|> 
<script>

function msg()
{
document.write("Hello world");
}

</script>

<form>
<input type="button" value="Click me" onclick="msg()">
</form>
</body>
</html>

Program Explanation: In the above code <script> define java script, 'function' is a keyword in java script that is used to define a user define function and 'msg()' is function's name.

'document.write' is used to print any given statement on output window and 'Hello world' its argument which print on output window after run this code. 

'onclick' is a JavaScript even which attach with a html button control, so as we will click on this button the 'msg()' function execute.   



INTRODUCTION OF VARIABLES

Variables are run time entity that is used to store data during run time and in JavaScript we have to use "var" keyword to declare any variable. 

Rules to naming a variable in JavaScript
1. Every variable should be declare with "var" keyboard.
Example: var a; 

2. Variable names should be always start with a character. 
Example: var a, var b12, var abc;

3. Blank spaces are not allow in any variable name
Example: var roll_no;   

4. Variable cannot declare with reserve keywords such var, break, for, name
Example: var name1;

Example of simple JavaScript program.
<script>
document.write("Hello Wolrd");
</script>

Explanation: in the above program <script> tag is used to insert java script code, "document.write" is a java script command that is used to print any given argument on output window and "Hello Word" is text argument.  

Program To Access Text Box Value By "dot" Operator

<html>
<title> Access text box value </title>
<body>
<form name="f">
Enter any number <input type="text" name="n">
<input type="button" value="Submit" onclick="abc()">
</form>

<script>
function abc()
{
alert(f.num.value)
}
</script>

</body>
</html>
Operators in JavaScript

In java script operators can be classify in the following categories.

Arithmetical Operators
Operator
Function
Example
+
Addition
C=A+B
-
Subtraction
C=A-B
*
Multiplication
C=A*B
/
Division
C=A/B


Logical Operators
Operator
Function
Example
&&
And
A > B && B > C
||
Or
A >33 B || A == 33
!
Not
A != 0

Relational Operators
Operator
Function
Example
< 
Less than
A < B
<=
Less than or Equal to
A <= B
> 
Greater than
A > B
>=
Greater than or Equal to
A >= B
=
Assignment
A = B
==
Comparison
A == B


No comments:

Post a Comment