0% found this document useful (0 votes)
16 views

Java Script-Djsnhv

The document provides an introduction to JavaScript including its history, advantages, disadvantages and basic syntax. It explains JavaScript data types, operators, conditional statements, loops and common functions like alert, confirm and prompt. Code examples are included to demonstrate various JavaScript concepts.

Uploaded by

Jeel Patoliya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Java Script-Djsnhv

The document provides an introduction to JavaScript including its history, advantages, disadvantages and basic syntax. It explains JavaScript data types, operators, conditional statements, loops and common functions like alert, confirm and prompt. Code examples are included to demonstrate various JavaScript concepts.

Uploaded by

Jeel Patoliya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Java Script

Presented By
1. Jeel Patoliya
2. Hemil Hapani
3. Het Bathani
4. Rushabh khimani
Introduction To Java Script

Brendan Eich first developed JavaScript, a computer


language, in about ten days in May 1995. The language,
formerly known as Mocha, later modified to LiveScript, and
is now known simply as JavaScript.
JavaScript is a lightweight, cross-platform, single-threaded,
and interpreted compiled programming language. It is also
known as the scripting language for webpages.
JavaScript is a weakly typed language (dynamically typed).
JavaScript can be used for Client-side developments as well
as Server-side developments.
ADVANTAGE AND DISADVANTAGE OF JAVA SCRIPT

ADVANTAGE DISADVANTAGE
Simple Syntax Less Secure

Client-side Execution Stucked Rendering

Validation on Browser No Multiple Inheritance


Simple Program Of Java Script
<Html>
<Head>
<Title>Simple Html Program</Title>
<script>
document.write("Hello World");
</script>
</Head>
<Body>

</Body>
</Html>
Data Types
Primitive Data Types
Number:-integer&Floating-point Number
Boolean:-True Or False
String:- A sequence of alphanumeric
Charaters

Composite Data Type(or Complex Data Type)


Object:-A named collection of data
Array:-A sequence of Values(an array is
actually a predefined object)

Specail data type


Null :- The only value is “null-to represent
nothing”
Undefined:-The only value is “undefined ”-to
represent the value of an
unintialized variable
Alert(),Confirm() and Prompt()
Alert Box
An alert box is often used if you want to make sure information comes through to the user.When an alert box pops up,
the user will have to click "OK" to proceed.

Syntax:-window.alert("sometext");

Confirm Box
A confirm box is often used if you want the user to verify or accept something.When a confirm box pops up, the user
will have to click either "OK" or "Cancel" to proceed.If the user clicks "OK", the box returns true. If the user clicks
"Cancel", the box returns false.

Syntax:-window.confirm("sometext");

Prompt Box
A prompt box is often used if you want the user to input a value before entering a page.When a prompt box pops up,
the user will have to click either "OK" or "Cancel" to proceed after entering an input value.If the user clicks "OK" the
box returns the input value. If the user clicks "Cancel" the box returns null.
Syntax:- window.prompt("sometext","defaultText");
Alert(),Confirm() and Prompt()
<Html>
<Head>
<Title> Alert confirm Prompt </Title>
<script>

window.alert("Incorrect Password");
confir=window.confirm("Do You Want Continue");
promp=window.prompt("Enter Value");

document.write(confir,'<br>');
document.write(promp);
</script>
</Head>
<Body>

</Body>
</Html>
Alert(),Confirm() and Prompt()
Operators In Java Script
1. Arithmetic Operators: • Equal to ==
• Addition + • Not equal to !=
• Subtraction - • Strict equal to ===
• Multiplication * • Strict not equal to !==
• Division / • Greater than >
• Remainder (Modulus) % • Less than <
• Increment ++ • Greater than or equal to >=
• Decrement -- • Less than or equal to <=
2. Assignment Operators: 4. Logical Operators:
• Assignment = • Logical AND &&
• Addition assignment += • Logical OR ||
• Subtraction assignment -= • Logical NOT !
• Multiplication assignment *= 5.Increment and Decrement Operators
• Division assignment /= • Increment ++
• Remainder assignment %= • Decrement --
Conditional Statements In Java Script
• IF:-Use if to specify a block of code to be executed, if a specified
condition is true
Syntax
if (condition) {
// block of code to be executed if the condition is
true
}

• Else..IF:- Use else to specify a block of code to be executed, if the


same condition is false
• if (condition) {
// block of code to be executed if the condition is
true
} else {
// block of code to be executed if the condition is
false
}
Conditional Statements In Java Script
• Else..IF…Else:- Use else if to specify a new condition to test, if the first condition is false
Syntax
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}

• Switch:-Use switch to specify many alternative blocks of code to be executed


Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Conditional Statement In Java Script
<Html>
<Head>
<Title>If..Else...If</Title>
<script>
let score = 75;
document.write("<h2>Grade Determination</h2>");
if (score >= 90) {
document.write("Grade: A<br>");
} else if (score >= 80) {
document.write("Grade: B<br>");
} else if (score >= 70) {
document.write("Grade: C<br>");
} else if (score >= 60) {
document.write("Grade: D<br>");
} else {
document.write("Grade: F<br>");
}
</script>
</Head>
<Body>
</Body>
</Html>
Loops In Java Script
The For Loop
loops through a block of code a number of times
The for statement creates a loop with 3 optional expressions:
for (expression 1; expression 2; expression 3)
{
// code block to be executed
}

<Html>
<Head>
<Title>For Loops</Title>
<script>
for (let i = 0; i < 5; i++) {
document.write( "The number is " + i + "<br>");
}
</script>
</Head>
<Body>
</Body>
</Html>
Loops In Java Script
The For In Loop
loops through the properties of an object
The JavaScript for in statement loops through the properties of an Object:
Syntax
for (key in object) {
// code block to be executed
}
<Html>
<Head>
<Title>For Loops</Title>
<script>
const numbers = [45, 4, 9, 16, 25];
for (let x in numbers) {
document.write( numbers[x],'<br>');
}
</script>
</Head>
<Body>
</Body>
</Html>
Loops In Java Script
The While Loop
loops through a block of code while a specified condition is true.
The while loop loops through a block of code as long as a specified condition is true.
Syntax
while (condition) {
// code block to be executed
}
Note:If you forget to increase the variable used in the condition, the loop will never end. This will crash your
browser.

<Html>
<Head>
<Title>While Loops</Title>
<script>
var i=0;
while (i < 10) {
document.write("The number is ",i,"<br>");
i++;
}
</script>
</Head>
<Body>
</Body>
</Html>
Loops In Java Script
The Do While Loop
The do while loop is a variant of the while loop. This loop will execute the code block once,
before checking if the condition is true, then it will repeat the loop as long as the condition is
true.
Syntax
do {
// code block to be executed
}
while (condition);
Note:If you forget to increase the variable used in the condition, the loop will never end.
This will crash your browser.
<Html>
<Head>
<Title>Do While Loops</Title>
<script>
var i=0;
do {
document.write("The number is " + i,'<br>');
i++;
}
while (i < 5)
</script>
</Head>
<Body>
</Body>
</Html>

You might also like