How do you declare a variable in JavaScript?
Using var, let, or const
What are data types in JavaScript?
String
Number
Boolean
Undefined
Null
BigInt
Symbol
What is the difference between == and ===?
== checks only value, while === checks value and type.
What is an array in JavaScript?
A collection of multiple values stored in a single variable.
let arr = [1, 2, 3, "hello"];
How do you check the data type of a variable?
Using typeof operator:
console.log(typeof 42); // "number"
console.log(typeof "Hello"); // "string"
What is an object in JavaScript?
A collection of key-value pairs.
let person = { name: "John", age: 25 };
console.log(person.name); // "John"
What is the this keyword?
Refers to the current object in different contexts.
What are template literals?
Strings with embedded expressions using backticks (``).
. How do you add elements to an array?
Using push() (adds to end) and unshift() (adds to start).
How do you remove elements from an array?
Using pop() (removes last) and shift() (removes first).
What is the difference between for and forEach loop?
for - Traditional loop for iterations.
forEach - Used on arrays for cleaner iteration.
What is a callback function?
A function passed as an argument to another function.
What is a promise in JavaScript?
A way to handle asynchronous operations.
How do you handle errors in JavaScript?
Using try...catch block.
What is the difference between map() and filter()?
map() - Transforms each element.
filter() - Filters elements based on a condition.
How do you convert a string to a number?
Using Number(), parseInt(), or parseFloat().
How do you check if a variable is an array?
Using Array.isArray().
How do you make an HTTP request in JavaScript?
Using fetch().
How do you remove duplicates from an array?
Using Set().
What is a closure in JavaScript?
A function that remembers the variables of its parent scope.
What is the spread operator?
Expands an array into individual elements.
let arr1 = [1, 2, 3];
let arr2 = [...arr1, 4, 5];
console.log(arr2);
What is the difference between for...in and for...of loops?
for...in - Iterates over object keys.
for...of - Iterates over values in an iterable like an array.
How do you merge two objects in JavaScript?
Using Object.assign() or spread operator.
What is the full form of (IIFE)?
Immediately Invoked Function Expression
What are JavaScript timers?
setTimeout() runs a function after a delay.
setInterval() runs a function repeatedly after a delay.