































































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
Examines JavaScript programming skills used in web development. Covers DOM manipulation, event handling, data validation, forms, flow control, cookies, object-oriented programming, and JS libraries. Candidates also demonstrate understanding of integrating JavaScript with HTML5 and CSS3. Recommended for aspiring front-end developers and web programmers.
Typology: Exams
1 / 71
This page cannot be seen from the preview
Don't miss anything!
































































Question 1. Which characteristic best describes JavaScript? A) Object-based, event-driven, platform-independent B) Strictly server-side, compiled language C) Platform-dependent, procedural language D) Static, strongly typed language Answer: A Explanation: JavaScript is characterized as object-based, event-driven, and platform-independent, meaning it relies on objects, responds to events like clicks or keypresses, and can run across different operating systems and browsers. Question 2. How does scripting differ from programming languages? A) Scripting languages are compiled; programming languages are interpreted B) Scripting languages automate tasks; programming languages develop complex applications C) Scripting languages require no syntax; programming languages require strict syntax D) There is no difference Answer: B Explanation: Scripting languages are often used for automating tasks and are typically interpreted, while programming languages are used to develop complex, standalone applications with more extensive features. Question 3. Which of the following is a property of JavaScript objects? A) Methods B) Algorithms C) Functions only D) Variables only Answer: A Explanation: Objects in JavaScript contain properties and methods; properties hold data, and methods are functions associated with objects. Question 4. JavaScript versions are primarily standardized by which organization?
C) ECMA International D) IEEE Answer: C Explanation: JavaScript standards are primarily set by ECMA International, specifically through ECMAScript specifications. Question 5. Which of the following best distinguishes client-side from server-side JavaScript? A) Client-side runs on the server; server-side runs in the browser B) Client-side handles user interface; server-side handles data processing C) Client-side is compiled; server-side is interpreted D) Both are the same Answer: B Explanation: Client-side JavaScript runs in the browser and manages user interaction, while server-side JavaScript (like Node.js) handles data processing and server tasks. Question 6. Why are comments important in JavaScript code? A) They execute code faster B) They make code more readable and maintainable C) They prevent syntax errors D) They increase code security Answer: B Explanation: Comments help developers understand and maintain code by providing explanations or annotations without affecting execution. Question 7. Which HTML tag is used to specify alternative content for users with JavaScript disabled? A)
Question 11. What is the main difference between string concatenation and arithmetic addition? A) Concatenation combines strings; addition sums numbers B) Concatenation multiplies strings; addition subtracts C) They are the same D) Concatenation converts numbers to strings automatically Answer: A Explanation: String concatenation joins strings together, while arithmetic addition sums numerical values. Question 12. Which operator is used for comparison in JavaScript? A) = B) == C) + D) && Answer: B Explanation: The == operator compares two values for equality, performing type coercion if necessary. Question 13. How does the logical AND (&&) operator work in JavaScript? A) Returns true if both operands are true B) Returns true if either operand is true C) Always returns false D) Always returns true Answer: A Explanation: The && operator evaluates to true only if both operands are true. Question 14. Which of the following has the highest precedence in JavaScript? A) Addition (+) B) Multiplication (*)
C) Assignment (=) D) Comparison (==) Answer: B Explanation: Multiplication has higher precedence than addition, assignment, or comparison operators. Question 15. Which event handler is used to respond to a mouse click? A) onload B) onclick C) onmouseover D) onkeydown Answer: B Explanation: The onclick event handler executes when a mouse click occurs on an element. Question 16. What does the expression '5 + "3"' evaluate to in JavaScript? A) 8 B) "53" C) Error D) null Answer: B Explanation: Adding a number and a string results in string concatenation, so the outcome is "53". Question 17. Which function is used to define a JavaScript function? A) function() B) def() C) define() D) declare() Answer: A Explanation: The function keyword is used to declare functions in JavaScript.
D) while Answer: B Explanation: The if...else statement allows conditional execution based on boolean expressions. Question 22. Which loop executes its block at least once before checking the condition? A) while B) do...while C) for D) forEach Answer: B Explanation: The do...while loop runs its body first, then checks the condition. Question 23. What is the primary purpose of a switch statement? A) Loop through items B) Execute code based on different values of an expression C) Handle exceptions D) Declare variables Answer: B Explanation: switch statements evaluate an expression and execute code blocks matching its value. Question 24. Which DOM object represents the main document content? A) window B) document C) navigator D) location Answer: B Explanation: The document object represents the entire HTML document. Question 25. How do you select an element by its ID in JavaScript?
A) getElementById() B) getElementsByClassName() C) querySelector() D) getElement() Answer: A Explanation: getElementById() retrieves an element with a specified ID. Question 26. Which property of an image element is used to change its source? A) src B) href C) alt D) title Answer: A Explanation: The src property specifies the URL of the image. Question 27. Which object contains information about the user's browser? A) window B) navigator C) document D) history Answer: B Explanation: The navigator object provides details about the browser. Question 28. How can you evaluate the current URL in JavaScript? A) window.location B) document.URL C) window.href D) document.location Answer: A
C) required D) both A and C Answer: D Explanation: The pattern attribute specifies a regular expression for validation, and required enforces input presence. Question 33. Which security risk involves malicious scripts executing in a trusted website? A) Cross-site scripting (XSS) B) Phishing C) Man-in-the-middle D) SQL injection Answer: A Explanation: XSS involves injecting malicious scripts into webpages viewed by other users. Question 34. Which JavaScript method is used to prevent form submission if validation fails? A) preventDefault() B) stopPropagation() C) halt() D) disable() Answer: A Explanation: preventDefault() stops the default action, such as submitting a form. Question 35. Which is a JavaScript library used for simplifying DOM manipulation? A) React B) jQuery C) Angular D) Vue Answer: B Explanation: jQuery is a popular library for simplifying DOM traversal and manipulation.
Question 36. What does AJAX stand for? A) Asynchronous JavaScript and XML B) Automatic JavaScript and XHTML C) Asynchronous Java and X D) Automated JavaScript and XML Answer: A Explanation: AJAX stands for Asynchronous JavaScript and XML, enabling asynchronous web communication. Question 37. Which method is used to send an HTTP request in AJAX? A) fetch() B) XMLHttpRequest.send() C) request() D) Both A and B Answer: D Explanation: Both fetch() and XMLHttpRequest.send() are used to send AJAX requests. Question 38. What does the Fetch API return? A) A Promise B) An XMLHttpRequest object C) A string D) An array Answer: A Explanation: fetch() returns a Promise that resolves to the response object. Question 39. Which web API provides access to the user's geographical location? A) Geolocation API B) Canvas API
Question 43. Which is an example of an asynchronous operation? A) fetch() B) alert() C) document.write() D) setTimeout() Answer: A Explanation: fetch() performs asynchronous data retrieval, returning a Promise. Question 44. How do you handle a Promise in JavaScript? A) then() and catch() B) resolve() and reject() C) execute() D) run() Answer: A Explanation: then() handles successful resolution, and catch() handles errors in Promise chains. Question 45. Which statement best describes a JavaScript class? A) A template for creating objects with shared properties and methods B) A function that executes once C) An HTML element D) A type of array Answer: A Explanation: Classes are templates for creating objects with shared structure and behavior. Question 46. What is the purpose of the prototype property in JavaScript? A) To add properties and methods to objects after creation B) To create a new object C) To define a class D) To assign a new value to an object
Answer: A Explanation: The prototype allows adding shared properties and methods to objects created via constructor functions. Question 47. Which method is used to create a new array based on an existing array? A) map() B) filter() C) reduce() D) All of the above Answer: D Explanation: map(), filter(), and reduce() are array methods used for creating new arrays based on existing ones. Question 48. How do you instantiate a new object from a constructor function? A) new ConstructorFunction() B) create ConstructorFunction() C) instantiate ConstructorFunction() D) define ConstructorFunction() Answer: A Explanation: The new keyword creates a new object instance from a constructor function. Question 49. Which JavaScript object is used for date and time operations? A) Date B) Time C) Calendar D) Chrono Answer: A Explanation: The Date object provides methods for handling date and time.
Answer: A Explanation: Declaring a variable with var outside functions makes it globally accessible. Question 54. What is a closure in JavaScript? A) A function bundled together with its lexical scope B) An object with private properties C) A loop that terminates early D) A script that closes a window Answer: A Explanation: Closures are functions that remember the scope in which they were created. Question 55. Which method is used to add an event listener to an element? A) addEventListener() B) attachEvent() C) bindEvent() D) on() Answer: A Explanation: addEventListener() attaches an event handler to an element in a standard way. Question 56. How do you remove an event listener in JavaScript? A) removeEventListener() B) detachEvent() C) deleteEvent() D) disconnectEvent() Answer: A Explanation: removeEventListener() detaches an event handler from an element. Question 57. Which property contains the URL of the current page? A) document.URL
B) window.location.href C) location D) All of the above Answer: D Explanation: All these properties provide the current page's URL information. Question 58. Which method is used to change the URL without reloading the page? A) location.assign() B) location.replace() C) history.pushState() D) All of the above Answer: D Explanation: These methods modify the URL or history entries without reloading. Question 59. Which object is used to manage browser history? A) window.history B) document.history C) navigator.history D) historyObject Answer: A Explanation: window.history provides methods to navigate through the session history. Question 60. Which regular expression method searches for a pattern in a string? A) test() B) match() C) exec() D) All of the above Answer: D
B) filter() C) reduce() D) forEach() Answer: A Explanation: map() returns a new array with each element transformed by the provided function. Question 65. How can you get the current date and time? A) new Date() B) Date.now() C) new Date().getTime() D) All of the above Answer: D Explanation: All these methods relate to current date and time information. Question 66. How do you generate a random number between 0 and 1? A) Math.random() B) Math.random(0, 1) C) Math.getRandom() D) Math.randomNumber() Answer: A Explanation: Math.random() returns a floating-point number between 0 (inclusive) and 1 (exclusive). Question 67. Which operator is used for bitwise AND? A) & B) && C) | D) | Answer: A Explanation: & performs bitwise AND operation between two numbers.
Question 68. Which keyword is used to declare a block-scoped variable? A) var B) let C) const D) B and C Answer: D Explanation: Both let and const declare block-scoped variables. Question 69. What is the purpose of the 'use strict' directive? A) Enforces stricter parsing and error handling B) Allows deprecated features C) Disables error checking D) Enables debugging mode Answer: A Explanation: 'use strict' enforces stricter rules to catch common coding mistakes. Question 70. Which statement about hoisting in JavaScript is true? A) Variable and function declarations are moved to the top of their scope B) Only variables are hoisted C) Only functions are hoisted D) Hoisting is not possible in JavaScript Answer: A Explanation: Both variable and function declarations are hoisted to the top of their scope, but not initializations. Question 71. Which method converts a string to a number? A) Number() B) parseInt()