



















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This review provides focused preparation in JavaScript programming fundamentals and client-side development. Topics include variables, functions, scope, control flow, DOM manipulation, events, debugging, and best practices. Practice questions strengthen coding logic and exam confidence.
Typology: Exams
1 / 91
This page cannot be seen from the preview
Don't miss anything!




















































































Question 1. Which keyword should be used to declare a variable whose value will never be reassigned? A) var B) let C) const D) static Answer: C Explanation: const creates a read‑only reference to a value, preventing reassignment after initialization. Question 2. In JavaScript, which operator tests both value and type equality? A) == B) != C) === D) !== Answer: C Explanation: The strict equality operator === returns true only if both operands are of the same type and have the same value. Question 3. What does the typeof operator return when applied to null? A) "null" B) "object" C) "undefined" D) "boolean" Answer: B
Explanation: Historically, typeof null yields "object" due to a legacy bug in the language specification. Question 4. Which method adds one or more elements to the end of an array and returns the new length? A) push() B) pop() C) shift() D) unshift() Answer: A Explanation: Array.prototype.push() appends elements to the end of the array and returns the updated length. Question 5. Which of the following statements about JavaScript’s event loop is correct? A) It executes callbacks only after the call stack is empty. B) It runs callbacks concurrently with the main thread. C) It processes events in a random order. D) It blocks the UI while waiting for network responses. Answer: A Explanation: The event loop checks the task queue and pushes callbacks onto the call stack only when the stack is empty, ensuring single‑threaded execution. Question 6. Which DOM method creates a new element node? A) document.createNode() B) document.createElement() C) document.newElement()
B) It is dynamically bound based on how the function is called. C) It inherits the this value from the enclosing lexical scope. D) It is always undefined in strict mode. Answer: C Explanation: Arrow functions do not have their own this; they capture the this value of the surrounding lexical context. Question 10. Which property of the Date object returns the number of milliseconds since 1 January 1970 UTC? A) getTime() B) valueOf() C) now() D) getUTCDate() Answer: A Explanation: date.getTime() returns the timestamp (epoch time) in milliseconds. Question 11. What is the output of the following code? let a = [1,2,3]; let b = a; b.push(4); console.log(a); A) [1,2,3] B) [1,2,3,4] C) [] D) undefined Answer: B Explanation: Arrays are objects; assigning b = a copies the reference, so both variables point to the same array.
Question 12. Which regular expression pattern matches a string that starts with “JS” and ends with a digit? A) /^JS.*\d$/ B) /JS.*\d/ C) /^JS\d$/ D) /JS\d$/ Answer: A Explanation: ^ anchors the start, .* matches any characters, \d matches a digit, and $ anchors the end. Question 13. Which method can be used to convert a string to a number without using parseInt or Number? A) "123".toString() B) "123".valueOf() C) "123" * 1 D) "123".length Answer: C Explanation: Multiplying a numeric string by 1 forces implicit type conversion to a number. Question 14. In ES6, which syntax creates a function that automatically returns the result of an expression? A) function() { return expr; } B) (expr) => {} C) (expr) => expr D) ()=>{ return expr; } Answer: C
D) Defers execution until the window.onload event. Answer: C Explanation: async allows the browser to fetch the script in parallel and run it as soon as it’s available, not waiting for other scripts or DOM parsing. Question 18. Which method of the XMLHttpRequest object sends a request to the server? A) open() B) send() C) request() D) fetch() Answer: B Explanation: After configuring the request with open(), calling send() actually transmits it. Question 19. Which of the following statements about the let keyword is FALSE? A) Variables declared with let are hoisted to the top of their block. B) let variables are scoped to the block in which they are defined. C) Re‑declaring a let variable in the same block causes a syntax error. D) let variables can be accessed before their declaration without error. Answer: D Explanation: Although let declarations are hoisted, they are in a temporal dead zone until the line where they are defined, so accessing them earlier throws a ReferenceError. Question 20. Which of the following is the correct way to prevent the default action of an event in a handler? A) event.stopPropagation(); B) event.preventDefault();
C) return false; D) event.cancel(); Answer: B Explanation: event.preventDefault() stops the default browser behavior associated with the event (e.g., following a link). Question 21. What will console.log([1,2,3] == [1,2,3]); output? A) true B) false C) undefined D) throws an error Answer: B Explanation: Arrays are objects; equality compares references, and two separate array literals have different references. Question 22. Which method creates a shallow copy of an array? A) slice() B) splice() C) copyWithin() D) concat() without arguments Answer: A Explanation: array.slice() without arguments returns a new array containing the same elements (shallow copy). Question 23. Which of the following statements about the navigator object is true? A) navigator.userAgent returns the current page URL.
Question 26. What does the bind method do when called on a function? A) Executes the function immediately. B) Returns a new function with a permanently bound this value. C) Changes the function’s name property. D) Copies the function into a new variable. Answer: B Explanation: Function.prototype.bind(thisArg, …) creates a new function where this is fixed to thisArg and any provided arguments are pre‑filled. Question 27. Which of the following is true about for...of loops? A) They iterate over object property names. B) They iterate over iterable objects such as arrays, strings, and Maps. C) They can be used to iterate over plain objects without a custom iterator. D) They are equivalent to for...in. Answer: B Explanation: for...of works with any iterable (objects implementing the iterator protocol), returning each value. Question 28. Which method removes the first element from an array and returns that element? A) pop() B) shift() C) splice(0,1) D) delete array[0] Answer: B Explanation: Array.prototype.shift() removes the element at index 0 and returns it.
Question 29. Which of the following is the correct syntax to define a class named Vehicle with a constructor that takes make and model? A) class Vehicle { function Vehicle(make, model) { this.make = make; this.model = model; } } B) class Vehicle { constructor(make, model) { this.make = make; this.model = model; } } C) function Vehicle(make, model) { this.make = make; this.model = model; } D) var Vehicle = class { make, model } Answer: B Explanation: In ES6 class syntax, the constructor method defines initialization logic. Question 30. Which statement about the Array.prototype.map() method is FALSE? A) It creates a new array with the results of calling a provided function on every element. B) It mutates the original array. C) It does not change the length of the array unless the callback returns undefined for some elements. D) It can be chained with other array methods. Answer: B Explanation: map() returns a new array and leaves the original array untouched. Question 31. What does the === operator return when comparing NaN with NaN? A) true B) false C) NaN D) throws an error Answer: B
Answer: B Explanation: strokeRect(x, y, w, h) draws the rectangle’s border without filling. Question 35. Which property of the Location object contains the fragment identifier (the part after #)? A) pathname B) hash C) search D) href Answer: B Explanation: location.hash returns the string including the leading #. Question 36. What will the following code log? console.log(typeof typeof 42); A) "number" B) "string" C) "undefined" D) "object" Answer: B Explanation: typeof 42 yields "number" (a string). Applying typeof again to that string returns "string". Question 37. Which of the following statements about strict mode ("use strict";) is correct? A) It allows the use of undeclared variables. B) It disables the this keyword. C) It throws an error when assigning to a non‑writable property.
D) It makes all functions asynchronous. Answer: C Explanation: In strict mode, attempts to assign to read‑only properties, delete undeletable properties, or use undeclared variables cause errors. Question 38. Which method can be used to convert a NodeList returned by document.querySelectorAll into an actual Array? A) Array.from(nodeList) B) nodeList.toArray() C) nodeList.slice() D) nodeList.map() Answer: A Explanation: Array.from() creates a new array from any iterable or array‑like object, including NodeList. Question 39. Which of the following is a correct way to prevent a form from submitting when a required field is empty, using JavaScript? A) event.returnValue = false; B) event.preventDefault(); inside the submit handler. C) form.submit(); inside the click handler. D) return true; at the end of the handler. Answer: B Explanation: Calling preventDefault() on the submit event stops the form submission. Question 40. Which of the following is the correct syntax to create a regular expression that matches a literal dot character? A) /\./
Question 43. Which of the following is the correct way to set a cookie named user with value John that expires in 7 days? A) document.cookie = "user=John; expires=7"; B) document.cookie = "user=John; max-age=604800"; C) document.cookie = "user=John; expires=Thu, 01 Jan 1970 00:00:00 GMT" D) document.cookie = "user=John; path=/; secure" Answer: B Explanation: max-age specifies the lifetime in seconds; 7 days = 7 × 24 × 60 × 60 = 604800 seconds. Question 44. Which method of the String object returns the position of the first occurrence of a specified value, or – 1 if not found? A) indexOf() B) search() C) match() D) locate() Answer: A Explanation: str.indexOf(substring) returns the zero‑based index or – 1. Question 45. In the context of AJAX, what does the acronym “XHR” stand for? A) XML Response B) eXtended Resource C) XMLHTTPRequest D) eXternal Resource Answer: C Explanation: XMLHttpRequest is the original object used for asynchronous HTTP requests.
Question 46. Which of the following statements about the let and var declarations is FALSE? A) let variables are block‑scoped, while var variables are function‑scoped. B) var declarations are hoisted to the top of their enclosing function or global scope. C) Re‑declaring a let variable in the same block is allowed. D) let does not create a property on the global window object when declared in the global scope. Answer: C Explanation: Re‑declaring a let variable in the same block causes a SyntaxError. Question 47. Which JavaScript feature allows you to import only specific functions from a module? A) require() B) import { func1, func2 } from 'module'; C) include() D) load() Answer: B Explanation: ES6 named imports let you select particular exports from a module. Question 48. Which of the following is a correct way to add a CSS class named active to an element with id nav? A) document.getElementById('nav').className = 'active'; B) document.getElementById('nav').classList.add('active'); C) document.getElementById('nav').setAttribute('class', 'active'); D) All of the above
C) window.query.id D) location.search.id Answer: A Explanation: URLSearchParams parses the query string and get() returns the value for the specified key. Question 52. Which of the following array methods does NOT change the original array? A) pop() B) splice() C) sort() D) filter() Answer: D Explanation: filter() returns a new array containing elements that pass the test; it leaves the source unchanged. Question 53. Which of the following is a valid way to create an Immediately Invoked Function Expression (IIFE)? A) function(){ /*...*/ }(); B) (function(){ /*...*/ })(); C) (() => { /*...*/ })(); D) Both B and C Answer: D Explanation: Wrapping the function in parentheses makes it an expression; both classic and arrow IIFE forms are valid. Question 54. Which of the following statements correctly describes the this value inside a regular function called as a method of an object?
A) It refers to the global object. B) It refers to the object that owns the method. C) It is always undefined in strict mode. D) It refers to the function itself. Answer: B Explanation: When a function is invoked as obj.method(), this inside the function points to obj. Question 55. Which of the following is the correct syntax to add an event listener for the submit event on a form with id myForm? A) document.getElementById('myForm').on('submit', handler); B) document.getElementById('myForm').addEventListener('submit', handler); C) $('#myForm').listen('submit', handler); D) document.getElementById('myForm').attachEvent('onsubmit', handler); Answer: B Explanation: addEventListener is the standard DOM method for attaching listeners. Question 56. Which of the following is true about the Array.prototype.reduce() method? A) It returns a single accumulated value after processing all elements. B) It creates a new array of the same length. C) It can only be used on numeric arrays. D) It mutates the original array. Answer: A Explanation: reduce() applies a reducer function to each element, producing a single output value.