JavaScript
JavaScript
JavaScript
Topic To Be Covered
PAGE
Note: Null is a special value mean value is nothing but Undefined mean
there is a value but not defined yet.
2
6. BigInt
7. Symbol
(ii) Non-Primitive Data Types : 1. Object (Collection of Data)
2. Array
3. Function
4. Date
Way to declare object or Ex of Object:
let student={
fullName:”Sahil”,
class: 10
};
Way to access key value in JavaScript : (i) console.log(student[“fullName”]);
Output: Sahil
b. Pre-Increment: ++ variable
b. Pre-Increment: -- variable
Console.log(a); Output: 3
(ii) “+=”
(iii)”-=”
(iv) “*=”
(v) “/=”
(vi) “%=”
(vii) “**”
(v)”<”,”<=”,”>”,”=>”
4. Logical Operator: (i) “Logical AND &&” (There are two statements and they both
should be true so the output will be true otherwise false)
let b=”3”;
let a=34;
let b=”3”;
(ii)”Logical OR ||” (There are two statements and one of both at least
should be true so the output will be true otherwise false)
let b=”3”;
let a=34;
let b=”3”;
(iii) Logical NOT ! (If the statement is true it will give FALSE and vise-versa):
Let b=4;
let a=3;
let b=4;
Conditional Statements:
1. If statement:
mode=”Dark-Mode”;
let color;
color = “Black”;
2. If-else statement:
mode=”Light”;
let color;
if (mode===”Light”) {
color=”White”;
}
else {
color=”Dark”;
}
7
Loops in JavaScript: Loops are used to execute a piece of code again & again
console.log(a);
} Output: 0,1,2,3,4,5
sum= 0 ;
for(a=0;a<=5;a++){
sum= sum + a;
console.log(sum); Output: 15
sum=sum+a;
a++
}
console.log(sum); Output: 15
3. Do-While loop:
let b=0;
do {
console.log(b);
b++;
} while(b<=5); Output: 0,1,2,3,4,5
let sumb=0;
let c=0;
do{sumb=sumb+c;
9
c++;
} while(c<=5);
console.log(sumb); Output: 15
console.log(val);
} Output: S,a,h,I,l
sizeofString=0
console.log(val);
sizeofString++
console.log(sizeofString); Output: 5
console.log(a);
Age:10
};
console.log(output);
Output: The Full NAME of the student is Sahil Kumar and Age is 10
console.log(quote);
Output: It's
(v) Carriage Return (\r): Moves the cursor to the beginning of the line. It’s
mostly used in conjunction with newline characters to control how text is
displayed.
Ex: const text = "Hello World!\rGoodbye";
console.log(text);
Output: Goodbye World! Hello
(i) str.toUpperCase()
(ii) str.toLoweCase()
(iii) str.trim() // Remove whitespaces at start andnd
(iv) str.slice(start index, end index) //end index value not included
Ex: a="0123456"
11
'0123456'
a.slice(1,4) Output: '123'
(v) str.concat(str2) //Joins string 2 with 1
(vi) str.replace/replaceAll(searchVal,newVal)
Ex: let a=12145;
Console.log(a.replace(“1”,”0”)) Output: 02145
let a=12145;
Console.log(a.replaceAll(“1”,”0”)) Output: 02045
(vii) str.charAt(index value)
Note: In JavaScript, strings are immutable, meaning they cannot be changed once
created.
12
Note: In JavaScript, array are mutable, meaning they can be changed once created.
Array Indices:
console.log(heroes[0]);
a=[1,2,3,4,5]
a[0]=55
Ex: console.log(arr.unshift(“Brinjal”,88));
Function in JavaScript: Block of code that performs a specific task, can be invoked(call)
whenever needed.
console.log(`Hello`)
console.log(printNameFunction());
function functionName(PARAMETER1,PARAMETER2..){
console.log(argument1,argument2..);
console.log(a+b);
console.log(functionDemo(3,4)); Output: 7
Note: Function parameters are like local variables they are block scope elements of a
function.
return a+b
console.log(sum(1,2)); Output: 3
15
Question: Create a function using the “function” keyword that takes a String as an
argument & returns the number of vowels in the string?
Answer:
Question: Repeat the same task again via arrow function to perform the same task.
Answer:
Note : In JavaScript function can be passed as parameters and we can also return the
value.
16