
Q91
Q91 Which method is commonly used to attach an event handler to an element in JavaScript?
addEventListener()
attachEvent()
onEvent()
bindEvent()
Q92
Q92 Which of the following is not a mouse event in JavaScript?
onclick
onmouseover
onmousemove
onchange
Q93
Q93 What does the following JavaScript code do?
document.getElementById('btn').onclick = function() {
alert('Button clicked');
};
Displays an alert when a button is clicked
Changes the text of a button
Reloads the page
Does nothing
Q94
Q94 What will be the result of this code if div1 is inside div2 in the HTML structure?
document.getElementById('div1').addEventListener('click', function(event) {
console.log('div1 clicked');
event.stopPropagation();
});
document.getElementById('div2').addEventListener('click', function() {
console.log('div2 clicked');
});
Only 'div1 clicked' will be logged
Only 'div2 clicked' will be logged
Both 'div1 clicked' and 'div2 clicked' will be logged
No message will be logged
Q95
Q95 What is the issue with this code?
button.addEventListener('click', doSomething); function doSomething() {
alert('Clicked');
}
Missing event listener
doSomething is not defined
Incorrect event type
No error
Q96
Q96 What is the main advantage of using AJAX in a web application?
Faster server response time
Increased security
Reduced server load and asynchronous requests
Simpler coding requirements
Q97
Q97 What is the difference between the Fetch API and XMLHttpRequest?
Fetch can only send asynchronous requests
Fetch returns a promise, making it easier to work with asynchronous operations
XMLHttpRequest is faster than Fetch
Fetch cannot handle responses in JSON format
Q98
Q98
Retrieves data from the URL
Updates data at the URL and logs the response
Deletes data at the URL
Submits data to the URL and logs the response
Q99
Q99 What does the finally block in a try...catch statement do?
It runs only if no errors occur
It runs after the try and catch blocks, regardless of the result
It runs as a cleanup process
It checks for any remaining errors
Q100
Q100 What is the output of this code?
try {
console.log('Start');
throw new Error('An error occurred');
console.log('End');
} catch(e) {
console.log('Caught an error');
}
'Start' 'End' 'Caught an error'
'Start' 'Caught an error'
'Caught an error'
'Start' 'An error occurred'
Q101
Q101 What will this code output?
try {
let x = y;
} catch(e) {
console.log(typeof e);
}
'undefined'
'object'
'string'
'error'
Q102
Q102 What will happen when this code is executed?
try {
null.foo();
}
catch(e) {
console.log(e.name);
} finally {
console.log('Done');
}
Logs 'TypeError' and 'Done'
Logs 'ReferenceError' and 'Done'
Only logs 'Done'
Causes a fatal error
Q103
Q103 Find the mistake in this code:
try {
let x = 10;
if(x > 5) {
throw 'Too high';
}
} catch(e) {
console.log('Error: ', e);
}
Incorrect use of throw
x > 5 should be x < 5
Error in the catch block
No error
Q104
Q104 Spot the error in this code:
try {
let obj = JSON.parse('{"name":"Alice"');
} catch(e) {
console.log('Parsing error:', e);
}
Missing closing brace in JSON string
Incorrect use of JSON.parse
Error in the catch block
No error
Q105
Q105 What is an arrow function in ES6?
A function that points to another function
A shorter syntax for writing function expressions
A function used for one-way data binding
A special function for asynchronous programming
Q106
Q106 What does the following ES6 code output?
let [a, b] = [1, 2];
console.log(a);
1
2
[1, 2]
undefined
Q107
Q107 What will this ES6 code output?
function multiply(a, b = 2) {
return a * b;
}
console.log(multiply(3));
3
6
undefined
NaN
Q108
Q108 What is a callback function in JavaScript?
A function that is scheduled to run after a set interval
A function that calls itself
A function passed into another function as an argument to be executed later
A function that runs immediately after declaration
Q109
Q109 What is "Callback Hell" in JavaScript?
A large number of nested callback functions that make the code hard to read and maintain
An error thrown by a failed callback function
A callback function that never gets executed
A standard method for handling asynchronous operations
Q110
Q110 What does the following code do?
function processData(callback) {
if (data) {
callback(null, data);
} else {
callback(new Error('No data'), null);
}
}
Throws an error if there's no data
Processes data asynchronously and executes the callback function
Logs data to the console
Creates a new data object
Q111
Q111 What is the output of this code? function doAsyncTask(cb) { setTimeout(() => { console.log('Async Task Calling Callback'); cb(); }, 1000); } doAsyncTask(() => console.log('Callback Called'));
'Async Task Calling Callback' then 'Callback Called' after 1 second
'Callback Called' then 'Async Task Calling Callback' after 1 second
'Async Task Calling Callback' and 'Callback Called' simultaneously
Nothing, it's an infinite loop
Q112
Q112 What is a Promise in JavaScript?
A function that executes asynchronously
A callback function that executes immediately
An object representing the eventual completion or failure of an asynchronous operation
A data structure for storing multiple callbacks
Q113
Q113 How does promise chaining work in JavaScript?
By returning a new promise from the callback of another promise
By executing multiple callbacks in parallel
By repeatedly calling the same promise
By automatically rejecting a promise after a set timeout
Q114
Q114 What is the output of this promise chain?
Promise.resolve(1)
.then((x) => x + 1)
.then((x) => {
throw new Error('My Error');
})
.catch(() => console.log('Caught'))
.then(() => console.log('Done'));
'Caught' then 'Done'
'My Error' then 'Done'
Just 'Caught'
Just 'Done'
Q115
Q115 Spot the error in this promise code:
let p = new Promise((resolve, reject) => {
resolve('Success');
reject('Failed');
}).then(result => console.log(result)).catch(error => console.log(error));
The promise should not call both resolve and reject
The .then() method is misplaced
The .catch() block is unnecessary
The promise does not handle asynchronous operations
Q116
Q116 What is the purpose of the async keyword in JavaScript?
To pause the execution of a function
To declare a function as asynchronous
To speed up a function
To handle multiple promises simultaneously
Q117
Q117 How does await work inside an async function?
It stops the entire program until the awaited promise resolves
It waits for a promise to resolve before continuing the execution of the async function
It sends a request to the server
It creates a new thread for asynchronous execution
Q118
Q118
Q119
Q119
It logs 'Error fetching data'
It returns 'Error fetching data'
It throws an error but doesn't catch it
It returns undefined
Q120
Q120
Incorrect use of await
Syntax error in fetch
No error handling for fetch failure
Missing async keyword

