




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which keyword creates a block‑scoped variable that cannot be reassigned? A) var B) let C) const D) static Answer: C Explanation: const declares a block‑scoped constant; its binding cannot be reassigned after initialization. Question 2. What is the result of typeof NaN? A) "number" B) "NaN" C) "undefined" D) "object" Answer: A Explanation: In JavaScript, NaN is a special numeric value, so typeof NaN returns "number". Question 3. Which operator has higher precedence? A) && B) || C) ?? (nullish coalescing) D) = (assignment) Answer: C Explanation: Nullish coalescing (??) has higher precedence than logical OR (||) and AND (&&), but lower than most arithmetic operators; assignment is lowest.
Question 4. Which loop will iterate over the values of an iterable object, such as an array? A) for...in B) while C) for...of D) do...while Answer: C Explanation: for...of iterates over the values of an iterable (arrays, strings, maps, etc.), whereas for...in iterates over property keys. Question 5. What will console.log(0 == false) output? A) true B) false C) TypeError D) undefined Answer: A Explanation: The == operator performs type coercion; 0 is coerced to false, so the comparison yields true. Question 6. Which of the following creates a function with lexical this binding? A) function foo() {} B) ()=>{} C) new Function('return this') D) Object.create(null) Answer: B Explanation: Arrow functions do not have their own this; they inherit it from the surrounding lexical scope.
Question 10. Which syntax creates an object with a prototype of Animal? A) let dog = new Animal(); B) let dog = Object.create(Animal.prototype); C) let dog = { __proto__: Animal }; D) let dog = Animal.clone(); Answer: B Explanation: Object.create(proto) creates a new object whose internal [[Prototype]] is the given prototype object. Question 11. How do you import a default export named utils from helpers.js? A) import { utils } from './helpers.js'; B) import utils from './helpers.js'; C) import * as utils from './helpers.js'; D) require('./helpers.js').default; Answer: B Explanation: Default exports are imported without curly braces using the name you choose. Question 12. Which statement correctly catches errors thrown inside an async function? A) try { await foo(); } catch (e) {} B) foo().then(null, err => {}); C) await try { foo(); } catch(e) {}; D) catch (e) { await foo(); } Answer: A Explanation: await inside a try block allows catching rejected promises as exceptions.
Question 13. What is the purpose of the finally block in a try…catch…finally statement? A) To execute code only if an error occurs B) To execute code only if no error occurs C) To execute code regardless of whether an error occurred D) To re‑throw the caught error Answer: C Explanation: finally runs after the try and catch blocks finish, no matter the outcome. Question 14. Which of the following correctly creates a resolved Promise with the value 42? A) new Promise(42) B) Promise.resolve(42) C) Promise(42) D) Promise.create(42) Answer: B Explanation: Promise.resolve(value) returns a promise that is already fulfilled with the given value. Question 15. In the event loop, which queue holds callbacks from setTimeout? A) Call Stack B) Microtask Queue C) Callback Queue (Task Queue) D) Promise Queue Answer: C
Answer: C Explanation: let cannot be redeclared in the same scope, while var can be redeclared and is function‑scoped. Question 19. Which of the following correctly creates a class that cannot be instantiated directly? A) class Abstract { constructor() { if (new.target === Abstract) throw new Error(); } } B) class Abstract { static abstract = true; } C) abstract class Abstract {} D) class Abstract { private constructor() {} } Answer: A Explanation: Using new.target inside the constructor prevents direct instantiation of the class. Question 20. How do you export multiple named values from a module? A) export default a, b; B) export { a, b }; C) module.exports = [a, b]; D) export * from './module' as a, b; Answer: B Explanation: Named exports are listed inside curly braces. Question 21. Which of the following statements about === is correct? A) It performs type coercion before comparison. B) It returns true when both operands are null and undefined. C) It checks both value and type for strict equality. D) It treats NaN as equal to itself.
Answer: C Explanation: === (strict equality) compares both type and value without coercion; NaN === NaN is false. Question 22. What will console.log([1,2,3] + [4,5]) output? A) [1,2,3,4,5] B) "1,2,34,5" C) "1,2,34,5" (as a string) D) "1,2,34,5" (same as B) Answer: B Explanation: The + operator converts both arrays to strings, resulting in "1,2,3" + "4,5" → "1,2,34,5". Question 23. Which method removes the first element of an array and returns it? A) pop() B) shift() C) splice(0,1) D) removeFirst() Answer: B Explanation: shift() removes the element at index 0 and returns that element. Question 24. What does Object.assign(target, source) do? A) Creates a deep clone of source. B) Copies enumerable own properties from source to target. C) Merges prototypes of both objects. D) Swaps the references of target and source.
Answer: A Explanation: JSON.parse() parses a JSON-formatted string and returns the corresponding JavaScript value. Question 28. What is the default value of window.location.href? A) The URL of the current page. B) null C) An empty string. D) "about:blank" Answer: A Explanation: window.location.href reflects the full URL of the document currently loaded in the window. Question 29. Which DOM method returns a live HTMLCollection of elements with a given class name? A) document.querySelectorAll('.myClass') B) document.getElementsByClassName('myClass') C) document.getElementsByTagName('myClass') D) document.getElementById('myClass') Answer: B Explanation: getElementsByClassName returns a live collection that updates automatically when the DOM changes. Question 30. How can you add a CSS class active to an element stored in variable el? A) el.class = 'active'; B) el.classList.add('active');
C) el.setAttribute('className', 'active'); D) el.style.addClass('active'); Answer: B Explanation: classList.add adds a class without overwriting existing ones. Question 31. Which of the following correctly prevents the default action of a form submission inside an event handler? A) event.stopPropagation(); B) event.preventDefault(); C) return false; D) event.cancel(); Answer: B Explanation: event.preventDefault() stops the browser’s default behavior for the event. Question 32. What does the async keyword before a function declaration guarantee? A) The function will always return a Promise. B) The function runs in a separate thread. C) The function cannot contain await. D) The function executes synchronously. Answer: A Explanation: An async function always returns a Promise, resolved with the returned value or rejected with an error. Question 33. Which of the following is a correct way to create a deep copy of a plain object obj? A) Object.assign({}, obj)
A) To disable all caching. B) To allow cross‑origin requests with proper CORS headers. C) To send credentials automatically. D) To encrypt the request body. Answer: B Explanation: Setting mode to 'cors' enables the browser to make a cross‑origin request, respecting CORS policies. Question 37. Which storage mechanism persists data even after the browser is closed? A) sessionStorage B) localStorage C) cookies with Session flag D) IndexedDB with temporary flag Answer: B Explanation: localStorage data remains until explicitly cleared; sessionStorage clears when the tab/window is closed. Question 38. How do you clear all items from localStorage? A) localStorage.removeAll(); B) localStorage.clear(); C) localStorage.deleteAll(); D) localStorage = {}; Answer: B Explanation: localStorage.clear() removes every key/value pair stored in the origin’s local storage.
Question 39. Which console method prints a stack trace without throwing an error? A) console.error() B) console.warn() C) console.trace() D) console.log() Answer: C Explanation: console.trace() outputs a stack trace to the console. Question 40. Which npm command adds a package as a development dependency? A) npm install package --save-dev B) npm install package --save C) npm add package - D D) npm install package - g Answer: A Explanation: --save-dev (or -D) records the package under devDependencies in package.json. Question 41. What does Babel primarily do? A) Bundles multiple files into one. B) Lints JavaScript code for style errors. C) Transpiles modern JavaScript syntax to older versions. D) Executes JavaScript in a virtual machine. Answer: C Explanation: Babel converts ES6+ code into backward‑compatible ES5 syntax.
Question 45. What does event.stopPropagation() prevent? A) The default action of the event. B) The event from reaching the target element. C) The event from bubbling up to ancestor elements. D) The event from being captured during the capture phase. Answer: C Explanation: stopPropagation stops further propagation in the bubbling (or capturing) phase. Question 46. Which of the following is NOT a valid way to create a Promise? A) new Promise((resolve, reject) => { /*...*/ }) B) Promise.resolve(value) C) Promise.reject(error) D) Promise.create(() => {}) Answer: D Explanation: There is no Promise.create method in the standard API. Question 47. Which statement about setTimeout is true? A) It guarantees execution after exactly the specified delay. B) The delay is a minimum; actual execution may be later. C) It blocks the main thread for the duration of the timeout. D) It returns the result of the callback function. Answer: B Explanation: setTimeout schedules a callback after at least the given delay; the event loop may delay execution further.
Question 48. What will console.log(typeof Symbol('id')) output? A) "symbol" B) "object" C) "string" D) "undefined" Answer: A Explanation: Symbol is a primitive type; its typeof result is "symbol". Question 49. Which of the following correctly creates a generator function? A) function* gen() {} B) function gen*() {} C) *function gen() {} D) generator function gen() {} Answer: A Explanation: The asterisk after the function keyword defines a generator. **Question 50. What is the output of the following code?
let a = 0; a += ++a + a++; ** A) 0 B) 1 C) 2
D) map.values() Answer: A Explanation: Map.prototype.keys() returns a new iterator object that contains the keys. Question 52. What will Array.from({ length: 3 }, (_, i) => i * 2) return? A) [0, 2, 4] B) [1, 2, 3] C) [2, 4, 6] D) [] Answer: A Explanation: Array.from creates an array of length 3 and maps each index i to i*2. Question 53. Which of the following statements about BigInt is true? A) It can be mixed with Number in arithmetic without conversion. B) It is created using the BigInt() constructor or by appending n to an integer literal. C) It is automatically serialized by JSON.stringify. D) It is a subtype of Number. Answer: B Explanation: BigInt values are created via BigInt(123) or 123n. Mixing with Number throws a TypeError. Question 54. Which of these is a valid way to add a static method info to a class Car? A) class Car { static info() {} } B) class Car { info() {} } C) Car.info = function() {}; after class definition
D) Both A and C Answer: D Explanation: A static method can be defined inside the class with static keyword or added later as a property on the constructor function. Question 55. Which statement correctly describes the this value inside an arrow function used as a method of an object? A) It refers to the object itself. B) It is undefined in strict mode. C) It inherits this from the surrounding lexical scope, not the object. D) It is always the global object. Answer: C Explanation: Arrow functions do not have their own this; they capture the this from the enclosing context. Question 56. What does the Object.freeze(obj) method do? A) Makes the object immutable – properties cannot be added, removed, or changed. B) Prevents the object from being garbage‑collected. C) Seals the prototype chain only. D) Converts the object into a frozen array. Answer: A Explanation: Object.freeze makes an object non‑extensible, and its existing properties become read‑only. Question 57. Which of the following is true about null and undefined? A) typeof null returns "null".