CIW JavaScript Specialist 4 — Questions and Answers
Question 1: Which built-in JavaScript object provides methods for working with dates and times?
- Time
- Calendar
- Date (Correct answer)
- DateTime
Correct answer: Date
The Date object provides methods to create, retrieve, and manipulate dates and times in JavaScript.
Question 2: What does the async keyword do when placed before a function declaration?
- Makes the function run in a separate thread
- Causes the function to always return a Promise (Correct answer)
- Disables error handling inside the function
- Converts the function to a generator
Correct answer: Causes the function to always return a Promise
An async function always returns a Promise, and allows the use of the await keyword inside it to pause execution until a promise settles.
Question 3: In JavaScript, which method is used to convert a string to an integer?
- Number()
- toInteger()
- parseInt() (Correct answer)
- Math.floor()
Correct answer: parseInt()
parseInt() parses a string argument and returns an integer of the specified radix, stopping at the first non-numeric character.
Question 4: What is event bubbling in the browser DOM?
- Events are captured from the root down to the target element
- After an event fires on a target element, it propagates upward through ancestor elements (Correct answer)
- Multiple events are grouped into a single batch for performance
- Events fired on hidden elements are suppressed
Correct answer: After an event fires on a target element, it propagates upward through ancestor elements
Event bubbling means an event triggered on a child element propagates up through its parent elements in the DOM tree unless stopped.
Question 5: Which JavaScript method removes the last element from an array and returns it?
- shift()
- unshift()
- pop() (Correct answer)
- splice()
Correct answer: pop()
Array.pop() removes the last element from an array, mutates the original array, and returns the removed element.
Question 6: What is the purpose of the try...catch statement in JavaScript?
- To asynchronously handle HTTP errors only
- To test code performance benchmarks
- To handle exceptions that may be thrown during code execution (Correct answer)
- To prevent variables from leaking into global scope
Correct answer: To handle exceptions that may be thrown during code execution
try...catch lets you run code in the try block and intercept any thrown errors in the catch block to handle them gracefully.
Question 7: Which JavaScript object stores key-value pairs and allows any value (including objects) as a key?
- Object
- Set
- Map (Correct answer)
- WeakRef
Correct answer: Map
Map is a built-in JavaScript collection that holds key-value pairs and remembers insertion order, accepting any value — including objects — as keys.
Which built-in JavaScript object provides methods for working with dates and times?