Which data type represents a sequence of characters in JavaScript?
object
string
boolean
number
What is the purpose of event.preventDefault() in form handling?
event.preventDefault()
Submits the form data asynchronously
Clears the form fields
Stops the form from submitting
Validates the form data
What does the 'throw' keyword do in JavaScript error handling?
Defines a custom error type
Generates a new error object
Catches a thrown error
Prints the error message to the console
What is the result of the expression: 10 % 3?
10 % 3
3
10
0
1
What is the value of 'x' after the following code is executed?
let x = 5; if (x > 10) { x = 10; } else { x = 0; }
5
undefined
What is the correct syntax to change the text content of an element with the ID 'myElement' to 'Hello World!'?
document.querySelector('#myElement').innerHTML = 'Hello World!';
document.getElementById('myElement').innerText = 'Hello World!';
document.querySelector('#myElement').textContent = 'Hello World!';
document.getElementById('myElement').textContent = 'Hello World!';
Which event is fired when a user clicks on an HTML element?
onmousedown
onmouseover
onload
onclick
How do you set the 'src' attribute of an image element with the ID 'profilePic' to 'new-image.jpg'?
document.getElementById('profilePic').setAttribute('src', 'new-image.jpg');
document.querySelector('#profilePic').src = 'new-image.jpg';
document.getElementById('profilePic').src = 'new-image.jpg';
document.querySelector('#profilePic').setAttribute('src', '/new-image.jpg');
What is the correct syntax to add an event listener to an element?
element.attachEvent('click', functionName)
element.addEventListener('click', functionName)
element.on('click', functionName)
element.addListener('click', functionName)
Which statement can be used to exit a 'switch' statement?
return
continue
exit
break