Sunteți pe pagina 1din 3

Jscript-Introduction

1.It is a Microsoft implementation.


2.Object based scripting language
3.Can run only in presence of interpreter Eg:Webserver or webbrowser
4.Lossely typed language-No need to declare variables.

Writing Code
1.Code is written in text format
2.Consists of statements, block consists of set of statements, variables ,immediate values
3.Statement-Consists of one or more items or symbols.
-Every new line is a new statement
-Also we can use semicolon Jscript terminator(;)
4.Block- A group of statements surrounded by some braces are called block.
-Used to create a function or conditional statements.
5.Comments-Single line  Eg: //comments
-Multi line  Eg: /* comments */
can be written as series of single line comments.
6. Assignemnts and equality ’ = ‘ symbol is used to assign a value to a variable
(name=”Senthil”)
 ‘==’(double equal to symbol) is used to compare any two
values whether they are equal or not
7.Expression valid combinations of variables, values ,operators, expressions
Eg: a= b+c
B= (a+c)*c

Jscript Variables:
1.Variables are used to store the values in the script.
2.Can retrieve and manipulate values.
3.Declaring variable Not necessary.But declaring is a good practice
use Var for declaring the variables.
Eg: var mim=”India”
4.Naming VariablesJscript a case sensitive scripting language. So “var Com” is not
“var com”
The variable name must start with a character or underscore or $
Subsequent letters can be characters, numbers, underscore or $
No reserved words should be used.
Valid variable names: Country, _Country,$country,
 invalid variable names: 8country, count&ry, var
If not assigned with any values but declared means, it will exists
in script.But undefined.
If not assigned means we can assign as “null”(var colo=”null”)
 But without assigning and declaring we should not keep any
variable. Jscript will throw run time error
Eg: function test()
{
Var country //correct
State=”Andhra” //correct
City //Wrogn. It can be var city or assigned
with values
}
5.Coercion- Automatic conversion of type of variables.
-The variables take types equivalent to the type of values stored in it.
-Also the coercion or type conversion is automatic some restrictions are
There
-Numbers can easily included in strings . But strings cannot included in
numbers directly
-We need to use parseInt (), parseFloat() functions to include strings into
number
-Eg: var a=10
Var b=”1”
Var c= 0
c += b+c //This will give the result c=0110.The string b is not
included in numbers. a,c also converted to strings.
c += parseInt(b)+c //This will give the result c=11;

Jscript Data types:


1. six types of data type- number, string, objects, Boolean, null, undefined.
2. String – Given with single or double quotation
-If quotation comes in the string, then use single quote
- Eg: “I love india” , ‘”Hi ”, told by him’, “324”
- Can contain one or more Unicode character.
- If contains zero character, zero length string (“”).
3. Octal,Hexa decimal, decimal number can be used.
4.Octal starts with ‘0’ (Eg: o12345670), Hexa decimal 0x1234abc
5.octal and hexa decimal can be negative.
6.Boolean: true or false.
7.Undefined: After declared but no values assigned means the value of variable is
undefined.
8.Null : no values and means nothing

Controlling Program flow:


1.Control of flow is to perform different actions at different conditions.
2.Conditional statements- If …If else…
3.Conditional Operators-Condition given in a statement with a question mark with two
statements. If condition passes one statement will be executed else other will be executed.
4.Loops: use conditional loops to execute the statements repeatedly.
5.For, For..in, while, do..while,switch
6.For : for (var i=0;i<n;i++) { statement }
7.For..in – stepping through all the properties of object.
- Moves through all the indexes in the array.
- For(i in arrName) { }
8.While : while (i>0){ statements … i--}
9.Using break : stop the loop execution.
10.Using continue: Goes to next iteration.

Jscript Functions:
1.Function performs some actions.
2.Returns values.
3.Get values-> Called arguments or parameter
4.Function may be with or without arguments.
5.Two type of functions: Built into the language, User defined.

Jscript Objects:
1.

S-ar putea să vă placă și