What is the correct way to add an event listener that logs 'Button Clicked!' to the console when a button with the ID 'myButton' is clicked?
document.querySelector('#myButton').addEventListener('click', () => console.log('Button Clicked!'));
document.querySelector('#myButton').onclick = console.log('Button Clicked!');
document.getElementById('myButton').addEventListener('click', function() { console.log('Button Clicked!'); });
document.getElementById('myButton').addEventListener('click', console.log('Button Clicked!'));
How can you change the text content of an HTML element using JavaScript?
All of the above
element.innerText = 'New text'
element.innerHTML = 'New text'
element.textContent = 'New text'
What does the querySelector() method return when it finds multiple matching elements in the DOM?
querySelector()
An array of all matching elements
The first matching element
null
The last matching element
In browser development, what does DOM stand for?
Data Object Manager
Dynamic Object Manipulation
Document Object Model
Digital Order Management
What does the Array.isArray() method return when passed an object?
Array.isArray()
false
undefined
true
"object"
object
Which of the following is NOT a built-in function in JavaScript for interacting with the user through the browser?
alert()
prompt()
confirm()
console.log()
What is the purpose of the 'else if' statement in JavaScript?
To declare a variable.
To execute a block of code if the preceding 'if' condition is true.
To define a loop that iterates a specific number of times.
To provide an alternative block of code to execute if the preceding 'if' or 'else if' conditions are false.
What is the value of 'x' after the following code is executed?
let x = 5; if (x > 10) { x = 10; } else { x = 0; }
5
0
10
What is the purpose of the 'do-while' loop in JavaScript?
To skip the current iteration of a loop.
To execute a block of code at least once, and then repeatedly as long as a condition is true.
To declare a function.
To execute a block of code only if a condition is true.
What is the difference between delete obj.property and obj.property = undefined?
delete obj.property
obj.property = undefined
You cannot set a property to undefined in JavaScript.
delete completely removes the property, while setting it to undefined keeps the property but with no value.
delete
They are functionally the same.
delete sets the property to null, while setting it to undefined removes it entirely.