Web Developer Interview Questions and Answers
Intermediate / 1 to 5 years experienced level questions & answers
Ques 1. What is the difference between HTML and XHTML?
HTML is more forgiving and allows for more flexibility, while XHTML is stricter and follows XML syntax.
Example:
HTML:Hello World
XHTML:Hello World
Ques 2. What is the purpose of the 'defer' attribute in a script tag?
The 'defer' attribute delays the execution of a script until the HTML parsing is complete.
Example:
Ques 3. Differentiate between sessionStorage and localStorage in HTML5.
sessionStorage stores data for the duration of a page session, while localStorage stores data with no expiration time.
Example:
sessionStorage.setItem('key', 'value');
localStorage.setItem('key', 'value');
Ques 4. How does CSS specificity work?
Specificity determines which CSS rule takes precedence when multiple conflicting rules target the same element.
Example:
div#myId {
color: blue;
}
#myId {
color: red;
}
Ques 5. What is responsive web design?
Responsive web design ensures that web applications render well on various devices and window or screen sizes.
Example:
@media screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
Ques 6. What is the purpose of the 'this' keyword in JavaScript?
The 'this' keyword refers to the current execution context and allows access to properties and methods of the current object.
Example:
const person = {
name: 'John',
greet: function() {
console.log('Hello, ' + this.name + '!');
}
};
person.greet();
Ques 7. Explain the concept of CORS (Cross-Origin Resource Sharing).
CORS is a security feature implemented by web browsers to restrict web pages from making requests to a different domain than the one that served the web page.
Ques 8. What is the purpose of the 'async' and 'await' keywords in JavaScript?
The 'async' keyword is used to declare an asynchronous function, and 'await' is used to pause the execution of the function until the Promise is settled.
Example:
async function fetchData() {
let response = await fetch('https://api.example.com/data');
let data = await response.json();
console.log(data);
}
Ques 9. How does the 'localStorage' differ from 'sessionStorage' in HTML5?
'localStorage' persists even when the browser is closed and reopened, while 'sessionStorage' data is only available for the duration of the page session.
Ques 10. What is the significance of the 'viewport' meta tag in HTML?
The 'viewport' meta tag controls the layout and scaling of the webpage on mobile devices, ensuring proper rendering on various screen sizes.
Example:
Ques 11. What are RESTful APIs, and how do they work?
RESTful APIs (Representational State Transfer) are web APIs that adhere to the principles of REST, utilizing standard HTTP methods for communication.
Ques 12. What is the purpose of the 'defer' attribute in a script tag?
The 'defer' attribute delays the execution of a script until the HTML parsing is complete.
Example:
Ques 13. Explain the concept of 'hoisting' in JavaScript.
Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope during the compilation phase.
Example:
console.log(x); // undefined
var x = 5;
Ques 14. Explain the 'same-origin policy' in the context of web security.
The 'same-origin policy' is a security measure that restricts web pages from making requests to a different domain than the one that served the web page.
Ques 15. How does the 'target' attribute work in HTML forms?
The 'target' attribute specifies where to open the linked document when submitting a form, such as '_blank' to open in a new tab.
Example:
Ques 16. Explain the concept of 'Promises' in JavaScript.
Promises are objects representing the eventual completion or failure of an asynchronous operation, allowing better handling of asynchronous code.
Example:
const fetchData = new Promise((resolve, reject) => {
// asynchronous code
});
Ques 17. Explain the purpose of the 'data-*' attribute in HTML.
The 'data-*' attribute is used to store custom data private to the page or application, accessible by JavaScript and CSS.
Example:
User Profile
Ques 18. What is the purpose of the 'async' attribute in a script tag?
The 'async' attribute in a script tag allows the script to be downloaded asynchronously, without blocking the HTML parsing, and then executed.
Example:
Ques 19. What is the purpose of the 'role' attribute in HTML?
The 'role' attribute is used to define the purpose or type of an element for accessibility, helping assistive technologies interpret content.
Example:
Ques 20. What is the purpose of the 'fetch' API in JavaScript?
The 'fetch' API is used to make HTTP requests and handle responses in a more flexible and modern way compared to the traditional 'XMLHttpRequest'.
Example:
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data));
Ques 21. What is the purpose of the 'transition' property in CSS?
The 'transition' property is used to create smooth transitions between different property values, allowing for animation effects.
Example:
div {
transition: width 2s, height 2s;
}
Ques 22. Explain the purpose of the 'transform' property in CSS.
The 'transform' property is used to apply 2D or 3D transformations to elements, such as scaling, rotating, and translating.
Example:
div {
transform: rotate(45deg);
}
Ques 23. Explain the concept of 'Progressive Enhancement' in web development.
Progressive Enhancement is a strategy where the core functionality and content are delivered to all users, with enhanced features provided to those with modern browsers or devices.
Ques 24. What is the purpose of the 'aria-*' attributes in HTML?
The 'aria-*' attributes are used to enhance the accessibility of web content by providing additional information to assistive technologies.
Example:
Ques 25. How does 'localStorage' differ from 'cookies' in web development?
'localStorage' allows for larger data storage on the client side, while cookies have size limitations and are sent with every HTTP request.
Ques 26. What is the purpose of the 'V8' engine in the context of JavaScript?
The 'V8' engine is an open-source JavaScript engine developed by Google, used in Chrome and Node.js, responsible for executing JavaScript code in the browser or server environment.
Ques 27. Explain the concept of 'Immutable Data' in JavaScript.
Immutable data cannot be changed once created, promoting safer state management and reducing bugs in applications.
Example:
const array = [1, 2, 3];
const newArray = [...array, 4];
Ques 28. Explain the purpose of the 'SQL JOIN' operation in database queries.
The 'SQL JOIN' operation combines rows from two or more tables based on a related column, allowing the retrieval of data from multiple tables in a single query.
Example:
SELECT users.username, orders.order_id FROM users
JOIN orders ON users.user_id = orders.user_id;
Ques 29. What is the purpose of the 'transition' property in CSS?
The 'transition' property is used to create smooth transitions between different property values, allowing for animation effects.
Example:
div {
transition: width 2s, height 2s;
}
Most helpful rated by users: