Js Important Questions
Js Important Questions
1. What is JavaScript?
Answer:
________________________________________________________________________________
Answer:
• String
• Number
• Boolean
• Undefined
• Null
• BigInt
• Symbol
• Object
• Arrays
• Functions
_______________________________________________________________________________
Answer:
_______________________________________________________________________________
Answer:
_______________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
A closure is a function that has access to its outer function's scope even
after the outer function has returned. It is created every time a function is
created.
________________________________________________________________________________
7. What is an IIFE?
Answer:
Example:
Sarvesh Sir
(function() {
console.log("IIFE");
})();
________________________________________________________________________________
Answer:
The this keyword refers to the object that the function is a property of. Its
value depends on how the function is called.
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
Sarvesh Sir
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
• bind: Returns a new function with a specific this value and arguments.
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
Sarvesh Sir
use strict enforces stricter parsing and error handling in your code. It helps
you write cleaner and more secure JavaScript.
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
• sessionStorage: Stores data for one session (data is lost when the tab
is closed).
________________________________________________________________________________
Answer:
The fetch API is used to make network requests (e.g., to fetch resources
from a server). It returns a promise that resolves to the response of the
request.
________________________________________________________________________________
Sarvesh Sir
Answer:
________________________________________________________________________________
Answer:
The typeof operator returns a string indicating the type of the operand.
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
________________________________________________________________________________
Answer:
The filter() method creates a new array with all elements that pass the test
implemented by the provided function.
________________________________________________________________________________
Answer:
1. Reverse an Array
2. Find Maximum and Minimum Element in an Array
3. Find the Second Largest Element
4. Check if an Array is Sorted
5. Remove Duplicates from an Array
6. Rotate an Array to the Right by k Steps
7. Move All Zeros to the End
8. Find Missing Number in an Array (1 to n)
9. Find the Intersection of Two Arrays
10. Find the Union of Two Arrays
String-Based Questions
Recursion
Miscellaneous
_______________________________ SOLUTIONS_________________________________
// 1. Reverse an Array
function reverseArray(arr) {
let reversed = [];
for (let i = arr.length - 1; i >= 0; i--) {
reversed[reversed.length] = arr[i];
}
return reversed;
}
Sarvesh Sir
// 5. Remove Duplicates
function removeDuplicates(arr) {
let unique = [];
for (let i = 0; i < arr.length; i++) {
let found = false;
for (let j = 0; j < unique.length; j++) {
if (arr[i] === unique[j]) {
found = true;
break;
}
}
if (!found) unique[unique.length] = arr[i];
}
return unique;
}
let n = arr.length;
let rotated = [];
for (let i = 0; i < n; i++) {
rotated[(i + k) % n] = arr[i];
}
return rotated;
}
// 8. Missing Number (1 to n)
function findMissingNumber(arr, n) {
let total = n * (n + 1) / 2;
let sum = 0;
Sarvesh Sir
}
return true;
}
}
return -1;
}
// 21. Factorial
function factorial(n) {
return n === 0 ? 1 : n * factorial(n - 1);
}
pop() {
if (this.stack.length === 0) return null;
let val = this.stack[this.stack.length - 1];
this.stack.length--;
return val;
}
}
}
while (i < arr1.length) result[result.length] = arr1[i++];
while (j < arr2.length) result[result.length] = arr2[j++];
return result;
}