What does the querySelector() method return when it finds multiple matching elements in the DOM?
querySelector()
The last matching element
The first matching element
null
An array of all matching elements
What is the primary role of the browser's JavaScript engine?
Styling web page elements
Defining the structure of a web page
Fetching data from a server
Interpreting and executing JavaScript code
Which of these is NOT a valid way to create a custom error in JavaScript?
throw { message: 'This is a custom error' }
throw new CustomError('This is a custom error')
throw new Error('This is a custom error')
throw 'This is a custom error'
What will the following code snippet log to the console: console.log((function(x) { return x * 2; })(5));
console.log((function(x) { return x * 2; })(5));
undefined
ReferenceError
10
5
What is the purpose of the typeof operator in JavaScript?
typeof
Checks if a variable is defined
Converts a variable to a string
Changes the data type of a variable
Determines the data type of a variable or expression
In JavaScript, what does it mean for a function to have a closure?
It can access variables from its surrounding scope, even after the outer function has finished executing.
It can access its own parameters.
It can be passed as an argument to other functions.
It can modify global variables.
How can you loop through the properties of an object myObject?
myObject
for (let i = 0; i < myObject.length; i++) {...}
while (myObject.hasNext()) {...}
myObject.forEach(property => {...})
for (let key in myObject) {...}
Why is JavaScript considered a 'dynamic' language?
It enforces strict data types for variables.
It enables changes to a webpage's content and behavior after it has loaded.
It is a very old programming language.
It allows for the creation of visually appealing websites.
What will the browser display after running this JavaScript code: alert('Hello') + ' World!'; ?
alert('Hello') + ' World!';
World!
Hello
Hello World!
An error message
What does 'client-side' JavaScript refer to?
JavaScript code used for database management
JavaScript code executed on a web server
JavaScript code used for server maintenance
JavaScript code executed on the user's web browser