JS Interview Questions
JS Interview Questions
BASIC :
1. What is JavaScript?
JavaScript is a high-level, dynamic programming language used to
create interactive and dynamic content on the web. It is a core
technology of the web, along with HTML and CSS.
syntax:
const name = "John";
console.log(`Hello, ${name}!`);
INTERMEDIATE :
function outerFunction() {
let outerVar = 'I am outside!';
return function innerFunction() {
console.log(outerVar); // 'I am outside!'
};
}
12. What is event delegation in JavaScript?
Event delegation is a technique of handling events by using a single
event listener to manage all events of a particular type within a parent
element, instead of adding multiple event listeners to individual child
elements.
try {
// code that may throw an error
} catch (error) {
// code to handle the error
} finally {
// code to run regardless of the outcome
}
ADVANCED :
21. What is the purpose of Object.create() method?
Object.create() creates a new object with the specified prototype object
and properties. It allows for more precise control over the inheritance
model:
Example :
const proto = { greet: function() { console.log('Hello'); } };
const obj = Object.create(proto);