50 Must-Know HTML, CSS and JavaScript Interview Questions by Ex-Interviewers - Blog
50 Must-Know HTML, CSS and JavaScript Interview Questions by Ex-Interviewers - Blog
HTML, CSS, and JavaScript are fundamental skills for any aspiring web developer, and
securing a job in this field can be a challenging endeavor, especially for beginners. A critical
part of the interview process is the technical interview, where your proficiency in these core
web technologies is thoroughly assessed. To help you prepare and boost your confidence,
we’ve compiled a list of the top 50 essential interview questions and answers covering HTML,
CSS, and JavaScript that are frequently asked in interviews.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 1/55
1. What Is Hoisting in JavaScript?
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Hoisting refers to JavaScript's behavior of moving variable and function declarations to the top
of their scope during the compilation phase. While declarations are hoisted, initializations are
not.
Visualized as:
var foo;
console.log(foo); // undefined
foo = 1;
console.log(foo); // 1
console.log(bar); // ReferenceError
let bar = 'value';
1 console.log(declared()); // Works
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 2/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
2 function declared() {
3 return 'Declared function';
4 }
5
6 console.log(expr); // undefined
7 console.log(expr()); // TypeError: expr is not a function
8 var expr = function () {
9 return 'Function expression';
10 };
Imports
Import statements are hoisted, making imported modules available throughout the file.
1 function test() {
2 var a = 1;
3 let b = 2;
4 const c = 3;
5 }
6 console.log(a); // ReferenceError
7 console.log(b); // ReferenceError
8 console.log(c); // ReferenceError
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 3/55
2. Initialization:
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
var a;
let b;
const c; // SyntaxError: Missing initializer
3. Redeclaration:
var : Allows redeclaration in the same scope.
let and const : Redeclaration is not allowed.
1 var x = 1;
2 var x = 2; // Valid
3
4 let y = 1;
5 let y = 2; // SyntaxError
4. Reassignment:
var and let : Reassignment is allowed.
const : Reassignment is not allowed.
const z = 1;
z = 2; // TypeError
5. Hoisting:
var : Hoisted and initialized to undefined .
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 4/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
1 console.log(a); // undefined
2 var a = 1;
3
4 console.log(b); // ReferenceError
5 let b = 2;
42 == '42'; // true
0 == false; // true
null == undefined; // true
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 5/55
Best Practice:
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Prefer === to avoid unexpected behavior caused by type coercion, except when comparing
against null or undefined .
Components:
1. Call Stack: Tracks function calls in a LIFO order.
2. Web APIs: Handle asynchronous tasks like timers and HTTP requests.
3. Task Queue: Stores tasks like setTimeout and UI events.
4. Microtask Queue: Handles high-priority tasks like Promise callbacks.
Execution Order:
1. Synchronous code executes first (call stack).
2. Microtasks are processed next.
3. Macrotasks are executed afterward.
Example:
1 console.log('Start');
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 6/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
2
3 setTimeout(() => console.log('Timeout'), 0);
4
5 Promise.resolve().then(() => console.log('Promise'));
6
7 console.log('End');
Output:
Start
End
Promise
Timeout
Benefits:
Reduces memory usage by limiting the number of listeners.
Dynamically handles added or removed child elements.
Example:
1 document.getElementById('parent').addEventListener('click', (event) => {
2 if (event.target.tagName === 'BUTTON') {
3 console.log(`Clicked ${event.target.textContent}`);
4 }
5 });
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 7/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Rules:
1. Default Binding: Refers to the global object ( window in browsers).
2. Implicit Binding: Refers to the object before the dot.
3. Explicit Binding: Defined using call , apply , or bind .
4. Arrow Functions: Lexically inherit this from the surrounding scope.
Example:
1 const obj = {
2 name: 'Alice',
3 greet() {
4 console.log(this.name);
5 },
6 };
7 obj.greet(); // Alice
localStorage :
Persistent storage (until manually cleared).
5MB limit per origin.
localStorage.setItem('key', 'value');
console.log(localStorage.getItem('key'));
sessionStorage :
Data cleared when the tab or browser is closed.
Limited to 5MB.
sessionStorage.setItem('key', 'value');
console.log(sessionStorage.getItem('key'));
<script> :
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 9/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
<script async> :
Loads scripts asynchronously.
Executes as soon as the script is ready, potentially before HTML parsing completes.
<script defer> :
Loads scripts asynchronously.
Executes only after the HTML parsing is complete.
<script src="main.js"></script>
<script async src="async.js"></script>
<script defer src="defer.js"></script>
Explore the difference between <script> , <script async> , and <script defer> on
GreatFrontEnd
undefined :
Indicates a variable has been declared but not assigned a value.
Undeclared:
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 10/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
1 let a;
2 console.log(a); // undefined
3
4 let b = null;
5 console.log(b); // null
.apply :
Accepts arguments as an array.
1 function sum(a, b) {
2 return a + b;
3 }
4 console.log(sum.call(null, 1, 2)); // 3
5 console.log(sum.apply(null, [1, 2])); // 3
Example:
1 const john = {
2 age: 42,
3 getAge: function () {
4 return this.age;
5 },
6 };
7
8 console.log(john.getAge()); // 42
9
10 const unboundGetAge = john.getAge;
11 console.log(unboundGetAge()); // undefined
12
13 const boundGetAge = john.getAge.bind(john);
14 console.log(boundGetAge()); // 42
15
16 const mary = { age: 21 };
17 const boundGetAgeMary = john.getAge.bind(mary);
18 console.log(boundGetAgeMary()); // 21
Common Uses:
1. Binding this : bind is often used to fix the this value for a method, ensuring it always
refers to the intended object.
2. Partial Application: You can predefine some arguments for a function using bind .
3. Method Borrowing: bind allows methods from one object to be used on another object.
Explore Function.prototype.bind on GreatFrontEnd
Arrow functions automatically bind the this value to the surrounding lexical scope, which
eliminates issues with context in methods. This behavior makes code more predictable and
easier to debug.
Example:
1 const Person = function (name) {
2 this.name = name;
3
4 this.sayName1 = function () {
5 console.log(this.name);
6 };
7
8 this.sayName2 = () => {
9 console.log(this.name);
10 };
11 };
12
13 const john = new Person('John');
14 const dave = new Person('Dave');
15
16 john.sayName1(); // John
17 john.sayName2(); // John
18
19 john.sayName1.call(dave); // Dave
20 john.sayName2.call(dave); // John
When to Use:
In scenarios like React class components, where methods are passed as props and need
to retain their original this context.
Explore the advantage of using the arrow syntax for a method in a constructor on
GreatFrontEnd
Prototypal inheritance allows objects to inherit properties and methods from other objects
through the prototype chain.
Key Concepts:
1. Prototypes:
Every JavaScript object has a prototype, which is another object from which it inherits
properties.
2. Prototype Chain:
JavaScript looks for properties and methods on the object and continues up the chain until it
finds the property or reaches null .
3. Constructor Functions:
Used with new to create objects and set their prototype.
1 function Animal(name) {
2 this.name = name;
3 }
4
5 Animal.prototype.sayName = function () {
6 console.log(`My name is ${this.name}`);
7 };
8
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 14/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Function Declaration:
function Person() {} is a standard function declaration. When written in PascalCase, it
conventionally represents a constructor function.
Function Call:
const person = Person() calls the function and executes its code but does not create a
new object.
Constructor Call:
const person = new Person() creates a new object, setting its prototype to
Person.prototype .
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 15/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Explore the difference between function Person(){} , const person = Person() , and
const person = new Person() on GreatFrontEnd
Function Expressions:
const foo = function () {
console.log('Function expression');
};
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 16/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
2. Object() Constructor:
3. Object.create() :
1 const proto = {
2 greet() {
3 console.log('Hello!');
4 },
5 };
6 const person = Object.create(proto);
7 person.greet(); // Hello!
4. ES2015 Classes:
1 class Person {
2 constructor(name, age) {
3 this.name = name;
4 this.age = age;
5 }
6 }
Example:
1 function multiplier(factor) {
2 return function (number) {
3 return number * factor;
4 };
5 }
6
7 const double = multiplier(2);
8 console.log(double(5)); // 10
ES2015 Class:
1 class Person {
2 constructor(name) {
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 18/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
3 this.name = name;
4 }
5
6 greet() {
7 console.log(`Hello, I’m ${this.name}`);
8 }
9 }
Key Differences:
Syntax: Classes are easier to read and write.
Inheritance: Classes use extends and super .
Explore ES2015 classes and ES5 constructors on GreatFrontEnd
Example:
parent.addEventListener('click', () => console.log('Parent clicked'));
child.addEventListener('click', () => console.log('Child clicked'));
mouseover
const fs = require('fs');
const data = fs.readFileSync('large-file.txt', 'utf8');
console.log(data); // Blocks until file is read
console.log('End of the program');
Asynchronous Functions
Allow the program to continue running without waiting for the task to finish
Enable other operations to proceed while waiting for responses or the completion of time-
consuming tasks
Are non-blocking, facilitating concurrent execution and enhancing performance and
responsiveness
Commonly used for network requests, file I/O, timers, and animations
Example:
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 21/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
XMLHttpRequest API
Example:
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 22/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
fetch() API
Example:
1 fetch('https://jsonplaceholder.typicode.com/todos/1')
2 .then((response) => {
3 if (!response.ok) {
4 throw new Error('Network response was not ok');
5 }
6 return response.json();
7 })
8 .then((data) => console.log(data))
9 .catch((error) => console.error('Fetch error:', error));
Process: Starts a fetch request, processes the response with .then() to parse JSON
data, and handles errors using .catch() .
Example:
1 fetch('https://api.example.com/data', {
2 method: 'GET', // or 'POST', 'PUT', 'DELETE', etc.
3 headers: {
4 'Content-Type': 'application/json',
5 },
6 });
2. Promise-Based Response
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 23/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
fetch() returns a Promise that resolves to a Response object representing the server's
reply.
3. Managing the Response
The Response object provides methods to handle the content, such as .json() ,
.text() , and .blob() .
Example:
fetch('https://api.example.com/data')
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error('Error:', error));
4. Asynchronous Nature
fetch() operates asynchronously, allowing the browser to perform other tasks while
awaiting the server's response.
Promises ( .then() , .catch() ) are processed in the microtask queue as part of the
event loop.
5. Configuring Request Options
The optional second parameter in fetch() allows configuration of various request
settings, including HTTP method, headers, body, credentials, and caching behavior.
6. Handling Errors
Errors such as network failures or invalid responses are captured and managed through
the Promise chain using .catch() or try/catch with async/await .
Learn how to explain AJAX in detail on GreatFrontEnd
page reloads.
Advantages
Enhanced User Experience: Updates content seamlessly without refreshing the entire
page.
Improved Performance: Reduces server load by fetching only the required data.
Maintains State: Preserves user interactions and client-side states within the page.
Disadvantages
Dependency on JavaScript: Functionality can break if JavaScript is disabled in the
browser.
Bookmarking Issues: Dynamic content updates make it difficult to bookmark specific
states of a page.
SEO Challenges: Search engines may find it hard to index dynamically loaded content
effectively.
Performance on Low-End Devices: Processing AJAX data can be resource-intensive,
potentially slowing down performance on less powerful devices.
Explore the benefits and drawbacks of using AJAX on GreatFrontEnd
Handling Responses
XMLHttpRequest: Uses the responseType property to manage different response
formats.
fetch(): Offers a unified Response object with .then methods for accessing data.
Managing Errors
XMLHttpRequest: Errors are handled via the onerror event.
fetch(): Errors are managed using the .catch method.
Controlling Caching
XMLHttpRequest: Managing cache can be cumbersome and often requires workaround
strategies.
fetch(): Directly supports caching options through its configuration.
Canceling Requests
XMLHttpRequest: Requests can be aborted using the abort() method.
fetch(): Utilizes AbortController for canceling requests.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 26/55
Tracking Progress
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 27/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Function: Functions are treated as objects and can be defined using declarations or
expressions.
Date: Represents dates and times.
RegExp: Used for defining regular expressions for pattern matching within strings.
Map: A collection of keyed data items, allowing keys of any type.
Set: A collection of unique values.
Identifying Data Types: JavaScript is dynamically typed, meaning variables can hold different
types of data at various times. The typeof operator is used to determine a variable's type.
Explore the variety of data types in JavaScript on GreatFrontEnd
2. Object.keys()
Returns an array containing the object's own enumerable property names.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 28/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
3. Object.entries()
Provides an array of the object's own enumerable string-keyed [key, value] pairs.
4. Object.getOwnPropertyNames()
Returns an array of all properties (including non-enumerable ones) directly found on the
object.
2. Array.prototype.forEach()
Executes a provided function once for each array element.
3. for...of Loop
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 29/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
4. Array.prototype.entries()
Provides both the index and value of each array element within a for...of loop.
Learn about the constructs used for iterating over object properties and array elements on
GreatFrontEnd
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 30/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Array vs. Object Spreads: Only iterables can be spread into arrays, while arrays can also
be spread into objects.
Rest Syntax
The rest syntax ( ... ) collects multiple elements into an array or object, functioning as the
opposite of spread syntax.
Function Parameters: Gathers remaining arguments into an array.
function addFiveToNumbers(...numbers) {
return numbers.map((x) => x + 5);
}
const result = addFiveToNumbers(4, 5, 6, 7); // [9, 10, 11, 12]
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 31/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
const { e, f, ...others } = { e: 1, f: 2, g: 3, h: 4 };
// e: 1, f: 2, others: { g: 3, h: 4 }
Understand the benefits of spread syntax and how it differs from rest syntax on
GreatFrontEnd
Performance: Typically offers better performance for larger datasets and frequent
modifications.
Plain Object
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 32/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Key Types: Primarily uses strings or symbols as keys. Non-string keys are converted to
strings.
Order: Does not guarantee the order of key insertion.
Size Tracking: Lacks a built-in property to determine the number of keys; requires manual
counting.
Iteration: Not inherently iterable. Requires methods like Object.keys() ,
Object.values() , or Object.entries() to iterate.
Example
1 // Map
2 const map = new Map();
3 map.set('key1', 'value1');
4 map.set({ key: 'key2' }, 'value2');
5 console.log(map.size); // 2
6
7 // Plain Object
8 const obj = { key1: 'value1' };
9 obj[{ key: 'key2' }] = 'value2';
10 console.log(Object.keys(obj).length); // 1 (keys are strings)
Discover the differences between a Map object and a plain object in JavaScript on
GreatFrontEnd
WeakMap and WeakSet exclusively use objects as keys, disallowing primitive values
like strings or numbers.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 33/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Memory Management:
Map and Set maintain strong references to their keys and values, preventing their
garbage collection.
WeakMap and WeakSet use weak references for keys (objects), allowing garbage
collection if there are no other strong references.
Key Enumeration:
Map and Set have enumerable keys that can be iterated over.
WeakMap and WeakSet lack a size property since their size can change due to
garbage collection.
Use Cases:
Map and Set are suitable for general-purpose data storage and caching.
WeakMap and WeakSet are ideal for storing metadata or additional object-related
information without preventing the objects from being garbage collected when they
are no longer needed.
Learn about the differences between Map / Set and WeakMap / WeakSet on GreatFrontEnd
Imagine you have an array of numbers and you want to double each number using the map
method.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 34/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
By utilizing arrow function syntax, the same outcome can be achieved more succinctly:
Explore a use case for the new arrow => function syntax on GreatFrontEnd
Example
1 function fetchData(callback) {
2 setTimeout(() => {
3 const data = { name: 'John', age: 30 };
4 callback(data);
5 }, 1000);
6 }
7
8 fetchData((data) => {
9 console.log(data); // { name: 'John', age: 30 }
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 35/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
10 });
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 36/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Example
1 // Array destructuring
2 const [a, b] = [1, 2];
3
4 // Object destructuring
5 const { name, age } = { name: 'John', age: 30 };
This syntax employs square brackets for arrays and curly braces for objects, allowing for
streamlined variable assignments directly from data structures.
Explore the concept of destructuring assignment for objects and arrays on GreatFrontEnd
Example
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 37/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
1 // Function declaration
2 hoistedFunction(); // Works fine
3 function hoistedFunction() {
4 console.log('This function is hoisted');
5 }
6
7 // Function expression
8 nonHoistedFunction(); // Throws an error
9 var nonHoistedFunction = function () {
10 console.log('This function is not hoisted');
11 };
Example
1 class Animal {
2 constructor(name) {
3 this.name = name;
4 }
5
6 speak() {
7 console.log(`${this.name} makes a noise.`);
8 }
9 }
10
11 class Dog extends Animal {
12 constructor(name, breed) {
13 super(name);
14 this.breed = breed;
15 }
16
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 38/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
17 speak() {
18 console.log(`${this.name} barks.`);
19 }
20 }
21
22 const dog = new Dog('Rex', 'German Shepherd');
23 dog.speak(); // Output: Rex barks.
In this example, the Dog class inherits from the Animal class, demonstrating how classes
facilitate inheritance and method overriding in JavaScript.
Explore the concept of inheritance in ES2015 classes on GreatFrontEnd
Example
1 function outerFunction() {
2 let outerVariable = 'I am outside!';
3
4 function innerFunction() {
5 console.log(outerVariable); // 'I am outside!'
6 }
7
8 innerFunction();
9 }
10
11 outerFunction();
In this scenario, innerFunction can access outerVariable because of lexical scoping rules,
which allow inner functions to access variables defined in their outer scope.
Explore the concept of lexical scoping on GreatFrontEnd
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 39/55
38. What is Scope in JavaScript?
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Scope in JavaScript defines the accessibility of variables and functions in different parts of the
code. There are three primary types of scope:
1. Global Scope: Variables declared outside any function or block are accessible throughout
the entire code.
2. Function Scope: Variables declared within a function are accessible only within that
function.
3. Block Scope: Introduced in ES6, variables declared with let or const within a block
(e.g., within {} ) are accessible only within that block.
Example
1 // Global scope
2 var globalVar = 'I am global';
3
4 function myFunction() {
5 // Function scope
6 var functionVar = 'I am in a function';
7
8 if (true) {
9 // Block scope
10 let blockVar = 'I am in a block';
11 console.log(blockVar); // Accessible here
12 }
13
14 // console.log(blockVar); // Throws an error
15 }
16
17 console.log(globalVar); // Accessible here
18 // console.log(functionVar); // Throws an error
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 40/55
39. What is the Spread Operator and How is it Used?
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
The spread operator ( ... ) in JavaScript allows iterable elements (like arrays or objects) to be
expanded into individual elements. It's versatile and can be used for copying, merging, and
passing array elements as function arguments.
Examples
1 // Copying an array
2 const arr1 = [1, 2, 3];
3 const arr2 = [...arr1];
4
5 // Merging arrays
6 const arr3 = [4, 5, 6];
7 const mergedArray = [...arr1, ...arr3];
8
9 // Copying an object
10 const obj1 = { a: 1, b: 2 };
11 const obj2 = { ...obj1 };
12
13 // Merging objects
14 const obj3 = { c: 3, d: 4 };
15 const mergedObject = { ...obj1, ...obj3 };
16
17 // Passing array elements as function arguments
18 const sum = (x, y, z) => x + y + z;
19 const numbers = [1, 2, 3];
20 console.log(sum(...numbers)); // Output: 6
The spread operator simplifies operations such as copying arrays or objects, merging multiple
arrays or objects into one, and spreading elements of an array as individual arguments to
functions.
Explore the concept of the spread operator and its uses on GreatFrontEnd
In JavaScript, the this keyword refers to the object that is executing the current piece of
code. Within event handlers, this typically points to the DOM element that triggered the
event. However, its value can change depending on how the handler is defined and invoked.
To ensure this references the intended context, techniques like using bind() , arrow
functions, or explicitly setting the context are employed.
These methods help maintain the correct reference for this within event handling functions,
ensuring consistent and predictable behavior across various event-driven scenarios in
JavaScript applications.
Explore the concept of this binding in event handlers on GreatFrontEnd
part of the selector and then traverse up the DOM tree to verify if those elements meet the
remaining parts of the selector.
For example, consider the selector p span . Browsers will first locate all <span> elements
and then check each span's ancestor chain to determine if it is within a <p> element. Once a
<p> ancestor is found for a given <span> , the browser confirms that the <span> matches
the selector and ceases further traversal for that element.
The efficiency of selector matching is influenced by the length of the selector chain—the
shorter the chain, the quicker the browser can verify matches.
Understand How Browsers Match CSS Selectors on GreatFrontEnd
44. What is the Box Model in CSS and How Can You
Control Its Rendering?
The CSS box model is a fundamental concept that describes the rectangular boxes generated
for elements in the document tree, determining how they are laid out and displayed. Each box
comprises a content area (such as text or images) surrounded by optional padding , border ,
and margin areas.
The box model is responsible for calculating:
The total space a block element occupies.
Whether borders and margins overlap or collapse.
The overall dimensions of a box.
Certain block-level elements like table , figure , and input have inherent width
values and may not expand fully.
Inline elements like span do not have a default width and will not expand to fit.
Content Dimensions: An element's height and width are determined by its content.
Box-Sizing: By default ( box-sizing: content-box ), padding and border are not
included in an element's width and height .
Note: Margins do not contribute to the actual size of the box; they affect the space outside
the box. The box's area is confined to the border and does not extend into the margin .
Additional Considerations
Understanding the box-sizing property is crucial as it alters how an element's height and
width are calculated.
box-sizing: content-box : The default behavior where only the content size is
considered.
box-sizing: border-box : Includes padding and border in the element's total width
and height , excluding margin .
Many CSS frameworks adopt box-sizing: border-box globally for a more intuitive sizing
approach.
Explore the Box Model and Its Control in CSS on GreatFrontEnd
Description:
none
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 45/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Hides the element; it does not occupy any space in the layout. All child elements are also
hidden. The element is treated as if it does not exist in the DOM.
block
The element occupies the full width available, starting on a new line.
inline
The element does not start on a new line and only occupies as much width as necessary.
inline-block
Combines characteristics of both inline and block . The element flows with text but can
have width and height set.
flex
Defines the element as a flex container, enabling the use of flexbox layout for its children.
grid
Defines the element as a grid container, allowing for grid-based layout of its children.
table
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 46/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
list-item
Makes the element behave like a <li> (list item) element, enabling list-specific styling such
as list-style-type and list-style-position .
For a comprehensive list of display property values, refer to the CSS Display | MDN.
Understand the CSS display Property with Examples on GreatFrontEnd
static : The default positioning. Elements flow naturally within the document. The top ,
right , bottom , left , and z-index properties have no effect.
relative : The element is positioned relative to its normal position. Adjustments using
top , right , bottom , or left move the element without affecting the layout of
surrounding elements, leaving a gap where it would have been.
absolute : The element is removed from the normal document flow and positioned
relative to its nearest positioned ancestor (an ancestor with a position other than
static ). If no such ancestor exists, it positions relative to the initial containing block.
Absolutely positioned elements do not affect the position of other elements and can have
width and height specified.
fixed : Similar to absolute , but the element is positioned relative to the viewport,
meaning it stays in the same place even when the page is scrolled.
sticky : A hybrid of relative and fixed . The element behaves like relative until it
crosses a specified threshold (e.g., scroll position), after which it behaves like fixed ,
sticking to its position within its parent container.
Understanding these positioning schemes is vital for controlling the layout and behavior of
elements, especially in responsive and dynamic designs.
Learn About Positioning Schemes in CSS on GreatFrontEnd
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 47/55
47. What Should You Consider When Designing for
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Multilingual Websites?
Designing and developing for multilingual websites involves various considerations to ensure
accessibility and usability across different languages and cultures. This process is part of
internationalization (i18n).
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 48/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Variable Lengths: Be aware that translations can alter text length, potentially affecting
layout and causing overflow issues.
Design Flexibility: Avoid rigid designs that cannot accommodate varying text lengths,
especially for headings, labels, and buttons.
Reading Direction
Left-to-Right (LTR) vs. Right-to-Left (RTL): Accommodate different text directions, such
as Hebrew and Arabic, by designing flexible layouts that can adapt to both LTR and RTL
orientations.
1 // English
2 const message = `I will travel on ${date}`;
3
4 // Chinese
5 const message = ` ${date} `;
Text in Images
Scalability Issues: Avoid embedding text within images, as it complicates translation and
accessibility. Use text elements styled with CSS instead to allow for easier localization.
Color Sensitivity: Be mindful that colors can carry different meanings and emotions across
cultures. Choose color schemes that are culturally appropriate and inclusive.
Understand Multilingual Design Considerations on GreatFrontEnd
Positioning Start on a new Flows along with Flows along with other
line and tolerates other content and content and allows other
no HTML allows other elements beside it.
elements next to elements beside it.
it (except when
you add float )
Can specify Yes Yes No. Will ignore if being
width and set.
height
align
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 51/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Layout Stability: The surrounding layout remains unaffected since the element's
space is preserved.
.element {
transform: translateX(50px);
}
1 .element {
2 position: absolute;
3 top: 20px;
4 left: 30px;
5 }
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 52/55
50. What Does * { box-sizing: border-box; } Do and
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
What It Does
By default, elements use box-sizing: content-box , where the width and height only
account for the content area. When you set box-sizing: border-box , the width and
height properties include the element's padding and border , but not the margin .
Comparison Table
Property box-sizing: content-box (default) box-sizing: border-box
Advantages
Intuitive Sizing: Including padding and border within the width and height makes it
easier to calculate the size of elements, aligning more closely with designers'
expectations.
Simplified Layouts: Prevents unexpected sizing issues, especially when adding padding
or border to elements, as it doesn't alter the total size.
Consistency Across Frameworks: Many CSS frameworks like Bootstrap, Tailwind, and
Bulma set box-sizing: border-box globally to maintain consistency and predictability in
element sizing.
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 53/55
11/06/2025, 18:53 50 Must-know HTML, CSS and JavaScript Interview Questions by Ex-interviewers | Blog
Conclusion
Congratulations on reaching the end of our comprehensive collection of HTML, CSS, and
JavaScript interview questions and answers! We hope this resource has equipped you with the
confidence and skills needed to excel in your upcoming interviews. Remember, consistent
practice is essential, so keep coding and revisiting these concepts until they become second
nature.
← Previous Next →
50 Must-know JavaScript Interview Top 30 React js Interview Questions and
Questions by Ex-interviewers Answers to Get Hired in 2025
Guides Roadmap
Front End Interview Playbook About
Front End System Design Playbook Team
React Interview Playbook Contact us
Behavioral Interview Playbook Advertise with us New
Become an affiliate
Careers
Blog
Medium
DEV Community
English (US)
© 2025 Codeney Pte Ltd. All rights reserved. Privacy Policy Terms of Service
https://www.greatfrontend.com/blog/50-must-know-html-css-and-javascript-interview-questions-by-ex-interviewers 55/55