JS_solved
JS_solved
Answers): 00:01:52 - What is JavaScript and its common uses? 00:02:12 - What are
template literals in JavaScript? 00:02:59 - What is hoisting? Provide an example.
00:04:09 - Difference between let, var, and const. 00:05:40 - Data types in
JavaScript. 00:07:55 - What is an array, and how to access its elements? 00:08:34 -
Difference between == and ===. 00:09:12 - Purpose of the isNaN function.
00:10:04 - What is null vs undefined? 00:10:44 - Use of the typeof operator. 👨💻
Intermediate Level JavaScript Interview Questions (JavaScript Interview Preparation
Guide): 00:11:08 - Purpose of the map method in JavaScript. 00:13:51 - Explain
event bubbling and event capturing. 00:20:25 - What are higher-order functions?
Provide an example. 00:22:18 - What is an IIFE (Immediately Invoked Function
Expression)? 00:24:36 - Explain closures in JavaScript. 00:30:12 - How do
setTimeout and setInterval work? 00:35:25 - Describe promises in JavaScript.
00:39:05 - Use of async and await in JavaScript. 00:42:57 - Difference between call,
apply, and bind. 00:50:01 - What is event delegation? 👨💻 JavaScript Interview
Questions and Answers for Experienced (JavaScript Interview Coding Questions):
00:57:46 - Explain the event loop in JavaScript. 00:59:47 - Difference between
promises and async/await. 01:03:56 - Purpose of the reduce method in arrays.
01:08:31 - Explain currying in JavaScript. 01:12:42 - What is a generator function
and its usage? 01:15:57 - What are weak maps and weak sets in JavaScript?
01:19:39 - How does JavaScript handle memory management? 01:21:25 - Difference
between shallow and deep copying. 01:25:57 - What is strict mode in JavaScript and
how is it enabled? 01:32:47 - Observer pattern and its relation to JavaScript.
// Function hoisting
greet(); // Output: "Hello!"
function greet() {
console.log("Hello!");
}
In the above example, the variable x is hoisted, but its assignment (x = 5) happens
later, so the first console.log(x) prints undefined. The function greet() is hoisted with
its definition, so it works even before its declaration.
4. Difference between let, var, and const:
var: Variables declared with var have function or global scope and can be re-
assigned.
let: Variables declared with let have block scope (limited to the block,
statement, or expression) and can be re-assigned.
const: Variables declared with const have block scope and cannot be re-
assigned. However, objects or arrays declared with const can still have their
properties or elements modified.
Example:
javascript
Copy
var a = 1;
let b = 2;
const c = 3;
a = 10; // Re-assignable
b = 20; // Re-assignable
// c = 30; // Error: Assignment to constant variable.
console.log(a, b, c);
5. Data types in JavaScript:
JavaScript has both primitive and non-primitive data types:
Primitive types: string, number, boolean, undefined, null, symbol, bigint
Non-primitive types: object (including arrays, functions, and others)
Example:
javascript
Copy
let name = "John"; // string
let age = 25; // number
let isActive = true; // boolean
let address = null; // null
let person; // undefined
let uniqueId = Symbol('id'); // symbol
6. What is an array, and how to access its elements?
An array is a data structure that stores multiple values in a single variable. Arrays
are indexed, and you can access their elements using the index (starting from 0).
Example:
javascript
Copy
let fruits = ['apple', 'banana', 'cherry'];
console.log(fruits[0]); // 'apple'
console.log(fruits[1]); // 'banana'
console.log(fruits[2]); // 'cherry'
7. Difference between == and ===:
== (loose equality): Compares values, performing type conversion if
necessary.
=== (strict equality): Compares both the value and the type, without type
conversion.
Example:
javascript
Copy
console.log(5 == '5'); // true (because type conversion happens)
console.log(5 === '5'); // false (because types are different)
console.log(a); // null
console.log(b); // undefined
10. Use of the typeof operator:
The typeof operator is used to determine the type of a variable or value.
Example:
javascript
Copy
console.log(typeof 'Hello'); // string
console.log(typeof 123); // number
console.log(typeof true); // boolean
console.log(typeof {}); // object
console.log(typeof undefined); // undefined
console.log(typeof Symbol()); // symbol
1. Purpose of the map method in JavaScript:
The map() method creates a new array populated with the results of calling a
provided function on every element in the array. It's commonly used to transform or
modify the elements of an array.
Example:
javascript
Copy
let numbers = [1, 2, 3, 4];
let doubled = numbers.map(num => num * 2);
<script>
document.getElementById('parent').addEventListener('click', function() {
alert('Parent clicked');
});
document.getElementById('child').addEventListener('click', function() {
alert('Child clicked');
});
</script>
When you click the button, the "Child clicked" message shows first, and then the
"Parent clicked" message appears, demonstrating event bubbling.
greet('Alice', () => {
console.log('How are you today?');
});
Here, the greet() function is a higher-order function because it takes a function
(callback) as an argument.
// setInterval
let counter = 0;
const intervalId = setInterval(() => {
counter++;
console.log('Interval count:', counter);
if (counter === 5) {
clearInterval(intervalId); // Stop the interval after 5 iterations
}
}, 1000);
if (success) {
resolve("Operation successful");
} else {
reject("Operation failed");
}
});
myPromise
.then(result => console.log(result)) // "Operation successful"
.catch(error => console.log(error)); // Will catch any rejection
fetchData();
In this example, await pauses execution until the fetch() request resolves and
returns data.
// Using call
greet.call(person, 'Hello', '!'); // Output: "Hello, Alice!"
// Using apply
greet.apply(person, ['Hello', '!']); // Output: "Hello, Alice!"
// Using bind
let boundGreet = greet.bind(person, 'Hi', '!');
boundGreet(); // Output: "Hi, Alice!"
<script>
document.getElementById('list').addEventListener('click', function(event) {
if (event.target.tagName === 'LI') {
alert(`You clicked on ${event.target.textContent}`);
}
});
</script>
In this example, the click event listener is attached to the ul element, and it checks
if the clicked element is an li. This way, we don't need to attach separate event
listeners to each li element.
HTML
➡️What is DOM?
➡️What are HTML Entities?
➡️What are Meta Tags?
➡️Explain Semantic Elements and how they differ from non-semantic elements.
🔹 CSS
➡️Explain the Box Model.
➡️What is Flexbox, and how does it work?
➡️Explain different CSS Positioning properties.
➡️What is Responsive Design, and how do you implement it?
🔹 JavaScript
➡️Difference between var, let, and const.
➡️Explain call, apply, and bind.
➡️Difference between splice and slice.
➡️Key ES6 Features.
🔹 React
➡️What is the Virtual DOM?
➡️Difference between Redux and Context API.
➡️What are Higher-Order Components (HOCs)?
🔹 HTML Interview Questions & Answers
1. What are the differences between HTML4 and HTML5?
Positio
Behavior
n
Example:
css
CopyEdit
.relative { position: relative; left: 20px; }
.absolute { position: absolute; top: 50px; left: 100px; }
.fixed { position: fixed; top: 0; left: 0; width: 100%; }
Property Effect
One-dimensional (row or
Layout Two-dimensional (rows & columns)
column)
Operat
Behavior
or
Example:
js
CopyEdit
console.log(5 == "5"); // true (type conversion)
console.log(5 === "5"); // false (different types)
Metho
Purpose
d
forEach
Iterates but does not return a new array
()
Example:
js
CopyEdit
let numbers = [1, 2, 3, 4];
// map()
let squared = numbers.map(num => num * num); // [1, 4, 9, 16]
// forEach()
numbers.forEach(num => console.log(num));
// filter()
let even = numbers.filter(num => num % 2 === 0); // [2, 4]
// reduce()
let sum = numbers.reduce((acc, num) => acc + num, 0); // 10