CSS Notes
CSS Notes
CSS Notes
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
CO
1.1 Features of JavaScript
1.8 Querying and setting properties and deleting properties, property getters and setters.
JavaScript is a scripting language that is created for showing HTML pages live. JavaScript does
not require any compilation. It is interpreted language. JavaScript can modify HTML page, writetext
in it, add or remove tags, change styles etc.
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
1. By object literal
example
<script>
var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
3. By using an object constructor (using new keyword)
Here, you need to create function with arguments. Each argument value can be assigned in
the current object by using this keyword.
The this keyword refers to the current object.
<script>
function emp(id,name,salary){
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);
We can define method in JavaScript object. But before defining method, we need to add
property in the function with same name as method. The example of defining method in object
is given below.
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
this.changeSalary=changeSalary;
function changeSalary(otherSalary){
this.salary=otherSalary;
}
}
e=new emp(103,"Sonoo Jaiswal",30000);
document.write(e.id+" "+e.name+" "+e.salary);
e.changeSalary(45000);
document.write("<br>"+e.id+" "+e.name+" "+e.salary);
</script>
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
In this example, x, y, and z, are variables, declared with the var keyword:
var x = 5;
var y = 6;
var z = x + y;
JavaScript Operators use either value or variable to compute some task. This lesson describes the
JavaScript operators with example, and operators precedence. JavaScript has following types
operators,
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
5. Conditional Operator (Ternary Operator)
6. Bitwise Operators
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
Example
<script>
var x = 10, y = 5;
document.writeln(x + y); // Addition: 15
document.writeln(x - y); // Subtraction: 5
document.writeln(x * y); // Multiplication: 50
document.writeln(x / y); // Division: 2
document.writeln(x % y); // Modulus: 0
document.writeln(x++); // x: 10, x become now 11
document.writeln(x); // x: 11
document.writeln(++x); // x become now 12, x: 12
document.writeln(x--); // x: 12, x become now 11
document.writeln(x); // x: 11
document.writeln(--x); // x become now 10, x: 10
</script>
Assignment Operators
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
*y
Division of operands and finally assign to result = result /
Division /= result /= y result = 17
left operand. y
Modulus Modulus of operands and finally assign to result = result
%= result %= y result = 2
left operand. %y
result = result &
y
AND operator compare two bits values 25
Bitwise AND &= return a results of 1, If both bits are 1. result &= y = 0000 0010 & result = 0
otherwise return 0. 0000 0101
= 0000 0000 =
0
result = result |
y
OR operator compare two bits values and =2|5
Bitwise OR |= return result of 1, If the bits are result |= y = 0000 0010 | result = 7
complementary. Otherwise return 0.
0000 0101
= 0000 0111 =
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
Example
<script>
var x = 17, y = 5;
var result = x; // Assignment to left operand(result) base on right operand(y).
document.writeln(result);
document.writeln(result += x);
document.writeln(result -= y);
document.writeln(result *= y);
document.writeln(result /= y);
document.writeln(result %= y);
document.writeln(result &= y);
result = 2; // Reassign value
document.writeln(result |= y);
document.writeln(result ^= y);
document.writeln(result <<= y);
document.writeln(result >>= y);
</script>
Comparison Operators
JavaScript comparison operator determine the two operands satisfied the given condition.
Comparison operator return either true or false.
Example
<script>
document.writeln(5 == 5); // true
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
Logical AND && If first operand evaluate and return a true, only that evaluate the second operand
otherwise skips.
Return true if both are must be true, otherwise return false.
Logical OR || Evaluate both operands,
Return true if either both or any one operand true,
Return false if both are false.
Logical NOT ! Return the inverse of the given value result true become false, and false become
true.
Example
<script>
document.writeln((5 == 5) && (10 == 10)); // true
document.writeln(true && false); // false
document.writeln((5 == 5) || (5 == 10)); // true
document.writeln(true || false); // true
document.writeln(5 && 10); // return 10
document.writeln(5 || 10); // return 5
document.writeln(!5); // return false
document.writeln(!true); // return false
document.writeln(!false); // return true
</script>
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
JavaScript conditional operator evaluate the first expression(operand), Base on expression result
return either second operand or third operand.
Example
document.write((10 == 10) ? "Same value" : "different value"
Bitwise AND & Return bitwise AND operation for given two operands.
Bitwise OR | Return bitwise OR operation for given two operands.
Bitwise XOR ^ Return bitwise XOR operation for given two operands.
Bitwise NOT ~ Return bitwise NOT operation for given operand.
Bitwise Shift Left << Return left shift of given operands.
Bitwise Shift Right >> Return right shift of given operands.
Bitwise Unsigned >>> Return right shift without consider sign of given operands.
Shift Right
Example
<script>
document.writeln(5 & 10); // return 0, calculation: 0000 0101 & 0000 1010 = 0000 0000
document.writeln(5 | 10); // return 15, calculation: 0000 0101 | 0000 1010 = 0000 1111
document.writeln(5 ^ 10); // return 15, calculation: 0000 0101 ^ 0000 1010 = 0000 1111
document.writeln(~5); // return -6, calculation: ~ 0000 0101 = 1111 1010
document.writeln(10 << 2); // return 40, calculation: 0000 1010 << 2 = 0010 1000
document.writeln(10 >> 2); // return 2, calculation: 0000 1010 >> 2 = 0000 0010
document.writeln(10 >>> 2); // return 2, calculation: 0000 1010 >>> 2 = 0000 0010
</script>
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
If Statement
if is used to check for a condition whether its true or not. Condition could be any expression that returns
true or false. When condition satisfies then statements following if statement are executed.
Syntax if(condition)
{
statement1
statement2
...
}
Example
<script>
if(5>4)
{
document.write("yes 5 is greater than 4");
document.write("<br />" + "JavaScript is fun");
document.write("<br />");
}
</script>
else statement
else statements are used with if statements. When if condition gets fail then else statement is
executed. Syntax
if(condition)
{
statements
}
else
{
Statements
}
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
Example
<script>
if(3>4)
{
document.write("True");
}
else
{
document.write("False");
}
</script>
else if statement
Suppose there are variety of conditions that you want to check. You can use
multiple if statements to do this task. All the if conditions will be checked one by one. But
what if you want that if one condition satisfies then don't perform further conditional
checks. At this point else if statement is what you need.
Syntax
if(condition)
{
statements
}
else if(condition)
{
statements
}
else
{
statements
}
When every condition fails then final else statement is executed.
Example
<script>
var a=3;
var b=4;
if(a > b)
{
Subject: Client Side Scripting Language Unit – I Basics of JavaScript Programming (10 Hrs.)
1.8 Querying and setting properties and deleting properties, property getters and setters.
Subject: Client Side Scripting Language (CSS) Compiled By: Musale D.S.
13