[go: up one dir, main page]

0% found this document useful (0 votes)
24 views27 pages

Class Xii Notes

Computer Java script
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views27 pages

Class Xii Notes

Computer Java script
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

CLASS NOTES

XII- WEB APPLICATION


Conditional
Description
Statement
Executes a block of code if a specified condition is
if statement
true.

Executes a block of code if the same condition of the


else statement
preceding if statement is false.

Adds more conditions to the if statement, allowing for


else if statement
multiple alternative conditions to be tested.

Evaluates an expression, then executes the case


switch statement
statement that matches the expression’s value.

Nested if else Allows for multiple conditions to be checked in a


if ( condition ) {
// If the condition is met,
//code will get executed.
}
if (condition1) {
// Executes when condition1 is true
if (condition2) {
// Executes when condition2 is true
}
}
if (1st condition) {
// Code for 1st condition
} else if (2nd condition) {
// ode for 2nd condition
} else if (3rd condition) {
// Code for 3rd condition
} else {
// ode that will execute if all
// above conditions are false
}
switch (expression) { if (condition1) {
case value1: // Code block 1
statement1; if (condition2) {
break; // Code block 2
case value2: } else {
statement2; // Code block 3
break; }
... } else {
case valueN: // Code block 4
statementN; }
break;
default:
statementDefault;
};
while (condition) statement

While vs Do … While
Parameter While Do-While
Loop body is executed, and
Loop body is executed after the given
Definition then the given condition is
condition is evaluated.
checked.
Variable Variables are initialized before the Variables may initialize
Initialization execution of the loop. before or within the loop.
Loop Type Entry Control Loop Exit Control Loop.

Semicolon is not used as a part of the Semicolon is used as a part


Semicolon
syntax. of the syntax.
while(condition){ do{
Syntax // loop body // loop body
While Loop • The while loop starts by
evaluating condition. If
condition evaluates to true,
Syntax the code in the code block
while (condition) gets executed.
{ • If condition evaluates to
// statement false, the code in the code
} block is not executed and
the loop ends.
let i = 1;
while (i < 10)
{
console.log(i);
i++;
}

// Output: // 1 // 2 // 3 // 4 // 5 // 6 // 7 // 8
// 9
do….while • The do...while loop is closely
related to while loop. In a
do...while loop, condition is
checked at the end of each
Syntax iteration of the loop, rather than
do at the beginning before the loop
runs.
{ • This means that code in a
// statement do...while loop is guaranteed to
run at least once, even if the
} condition expression already
while (condition); evaluates to true.
let i = 1;
do
{
console.log(i);
i++;
} while (i < 10);
// Output: // 1 // 2 // 3 // 4 // 5 // 6 //
7 // 8 // 9
For loop
❖initialization - This expression runs before the execution of the first
loop, and is usually used to create a counter.
❖condition - This expression is checked each time before the loop
runs. If it evaluates to true, the statement or code in the loop is
executed. If it evaluates to false, the loop stops. And if this
expression is omitted, it automatically evaluates to true.
❖finalExpression - This expression is executed after each iteration
of the loop. This is usually used to increment a counter, but can be
used to decrement a counter instead.
Syntax:
• for (initialization; condition; finalExpression)
• {
• statement
• }
for (let i = 0; i < 9; i++)
{
console.log(i);
}
// Output: // 0 // 1 // 2 // 3 // 4 //
5 // 6 // 7 // 8
ARRAY OBJECT

• The Array object, as with arrays in other


programming languages, enables storing a
collection of multiple items under a single variable
name, and has members for performing common
array operations.
• lenght()
• concat()
• pop()
• push()

• Reverse()
• Short
Ways to create an Array []
• const cars = ["Tomato", "Potato", "Chili"];
• const cars = [
"Tomato",
"Potato",
"Chili"
];
• const cars = [];
cars[0]= "Tomato";
cars[1]= "Potato";
cars[2]= "Chili";
• const cars = new Array("Saab", "Volvo", "BMW");
//Program to create an array.
<html>
<body>
<script>
var i;
var fruits=new Array();
fruits[0]="apple";
fruits[1]="banana";
fruits[2]="orange";
for(i=0;i<fruits.length;i++)
{
document.write(fruits[i]+"<br>");
}
</script>
</body>
</html>
CREATING AN ARRAY
• Using an array literal is the easiest way to
create a JavaScript Array.

• Syntax:
const array_name = [item1, item2, ...];
POP()

The pop() method removes (pops) the


last element of an array.
The pop() method changes the original
array.
The pop() method returns the removed
element.
PUSH()

• The push() method adds new items to


the end of an array.
• The push() method changes the length
of the array.
• The push() method returns the new
length.
REVERSE()

• The reverse() method reverses the


order of the elements in an array.
• The reverse() method overwrites the
original array.
SORT()

• The sort() method sorts the elements


of an array.
• The sort() method sorts the elements
as strings in alphabetical and ascending
order.
• The sort() method overwrites the
original array.
CONCAT()

• The concat() method concatenates


(joins) two or more arrays.
• The concat() method returns a new
array, containing the joined arrays.
• The concat() method does not change
the existing arrays.

You might also like