Java Script-Djsnhv
Java Script-Djsnhv
Presented By
1. Jeel Patoliya
2. Hemil Hapani
3. Het Bathani
4. Rushabh khimani
Introduction To Java Script
ADVANTAGE DISADVANTAGE
Simple Syntax Less Secure
</Body>
</Html>
Data Types
Primitive Data Types
Number:-integer&Floating-point Number
Boolean:-True Or False
String:- A sequence of alphanumeric
Charaters
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
}
<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>