[Go to site: main page, start]

0% found this document useful (0 votes)
2 views10 pages

Java Script

The document provides an overview of JavaScript data types, arithmetic operators, assignment operators, comparison operators, and control flow statements such as if, if-else, and if-else if statements. It includes examples of each concept, demonstrating how to use variables, operators, and conditional logic in JavaScript. Additionally, it covers the use of the Google Chrome console for debugging and logging outputs.
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)
2 views10 pages

Java Script

The document provides an overview of JavaScript data types, arithmetic operators, assignment operators, comparison operators, and control flow statements such as if, if-else, and if-else if statements. It includes examples of each concept, demonstrating how to use variables, operators, and conditional logic in JavaScript. Additionally, it covers the use of the Google Chrome console for debugging and logging outputs.
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

➔ JavaScript Data Types

1). What is Data Types:

Var x = “Hello World”;


|
Type of value is Data Type
 Different type of Data Types:
Var x = “hello World”; ------------> String
Var x= 25; ------------------> Number
Var x = true; -------------------->Boolean
Var x= [“HTML” , “CSS” ,”JS”]; ------> Array
Var x = null; ----------> Null
Var x; ----------------> Undefined

Example-:
Code

<!DOCTYPE html>
<html>
<head>
<title> JavaScript</title>
<script>
Var x = ‘y’;
X = -34.50;
X = false;
X = undefined;
X = [“html” , “CSS” , “js”];
X={
Name : “gautam singh”,
Country: “india”
}
X= “34”;
[Link](x);
[Link](“<br>”);
[Link](typeof x);
</script>
</head>
<body>
<script>

Var z;
[Link](typeof z);

</script>
</body>
</html>
➔ JavaScript Arithmetic Operators

1). Different Type of Arithmetic Operators:

Operator-: Description
1. + -: Addition
2. - -: subtraction
3. * -: Multiplication
4. ** -: Exponentiation
5. / -: Division
6. % -: Modulus(Remainder)
7. ++ -: increment
8. -- -: Decrement

Example -:

Code-:

<!DOCTYPE html>

<html>

<head>

<title> JavaScript </title>

<script>

Var a = 10;

Var b = 3;

Var c = a+b*2;

[Link](b+10);

</script>

</head>

<body>

</body>

</html>
→JavaScript Assignment Operators

Different Type of Assignment Operators:

Operator Example Same as

1. = x=y x=y
2. += x+=y x=x+y
3. -= x-=y x=x–y
4. *= x *= y x=x*y
5. /= x /= y x = x/y
6. %= x%=y x=x%y
7. **= x **= y x = x ** y

Example -:

Code-:

<!DOCTYPE html>

<html>

<head>

<title> JavaScript </title>

<script>

Var a = 10;

Var b = 3;

a += b

[Link](a);

</script>

</head>

<body>

</body>

</html>
➔ JavaScript Google Chrome Console

Example -:

Code-:

<!DOCTYPE html>

<html>

<head>

<title> JavaScript </title>

<script>

Var x = 50;

[Link](x+20);

[Link]([1,2,3,4]);

[Link]([1,2,3,4]);

[Link](“error’);

Start→ [Link](“test”);

[Link](“this is just warning”);

[Link](“this is just warning”);

[Link](“this is just warning”);

[Link](“this is just warning”);

End→ [Link](“test”);

[Link]();

</script>

</head>

<body>

</body>

</html>

1. Direct console code-:

>[Link](“hello world”);
>document
>[Link](“main”)
>[Link](“main”).innerText
→ JavaScript comparison Operators

1).
Var x = 15;
Var y = 25;

x>y →(true)

• Different type of comparison operators:

Operator
1. == -: equal
2. === -: equal value and equal type
3. != -: not equal
4. !== -: not equal value or not equal type
5. > -: greater than
6. < -: less than
7. >= -: greater than or equal to
8. <= -: less than or equal to

Example 1:

<script>
Var a = 10;
Var a = “10”;
[Link](a==b);
[Link](a===b);
[Link](5 != 4);
[Link](5 != 5);
[Link]( 5 !== 5);
[Link]( 5> 3);
[Link](5<6);
[Link](4 > = 4);
[Link](4 <=4);

</script>
➔ JavaScript if Statement

What is if Statement ? :

1. If -------> conditions --------------> False -------> Out

True

Statement
Ex-: if

Today is Monday -----> False ---> Out

True

Print “Mon”

2. If Statement in JavaScript:

If(Condition True){

➔ If Statement in JavaScript:

1. Var x = 15
If(x > 10 ){
[Link](“ X is Greater”);
}
2. Var x =5;
If(x > 10){ // error
[Link](“x is Greater”);
}
➔ JavaScript Logical Operator

What are Logical Operator?

If -----> Conditions 1 ---> False


Conditions 2---> False ------> Out
|
true
|
Statement
 Different type of logical Operators:

Operator
&& = Logical AND
|| = Logical OR
! = Logical NOT
1. If Statement with Logical AND:

Code-:

If( Condition 1 && Condition 2){

Example-:

<script>

Var age = 20;

If( age >= 18 && age <= 21){

[Link](“yes you are eligible”);

</script>

2. If statement with Logical OR:

Code-:

If( Condition 1 || Condition 2){

Example -:

<script>

Var a = 10;

Var b = 15;

If(a >= 12 || b <= 14){

[Link](“yes you are eligible”);

</script>

3. If statement with Logical NOT:

Code-:

If !(Condition){

}
Example -:

<script>

Var a = 30;

Var b = 15;

If(!a >= 12){

[Link](“yes you are eligible”);

</script>

➔ JavaScript if Else Statement

What is if else statement ?

If ------------> Conditions ---> False -------> Statement 2


|
True
|
Statement

Example-:
 If else statement in JavaScript:

Code-: if(Condition True){


Statement for true
} else{
Statement For False
}

Example-:

Var x = 15;

If( x>30){

[Link](“X is Greater”);

}else{

[Link](“X is smaller”);

➔ JavaScript if else if Statement

1).
1).

If(Condition 1){

}else if(Condition 2){

} else{

2).
Example-:

If(time < 10){


[Link](“good morning”);
} else if(time < 20){
[Link](“good day”);
}else{
[Link](“good evening”);
}

If else if Statement in javaScript:

Percentage: Grade

80 – 100% Merit

60 – 79% 1st Division

45 – 59% 2nd Division

33 - 44% 3rd Division

Less than 33% fail

Code-:

<script>

Var per = 55;

If(per >= 80 && per <=100){

[Link](“you are in merit.”);

} else if(per >= 60 && per <80){

[Link](“you are in 1st”);

} else if(per >= 45 && per < 60 ){

[Link](“you are in 2nd”);


}
else if(per >= 33 && per < 45){
[Link](“pass”);

Else{

[Link](“fail”);

</script>

You might also like