What is the correct syntax to change the text content of an element with the ID 'myElement' to 'Hello World!'?
document.querySelector('#myElement').textContent = 'Hello World!';
document.getElementById('myElement').innerText = 'Hello World!';
document.getElementById('myElement').textContent = 'Hello World!';
document.querySelector('#myElement').innerHTML = 'Hello World!';
What is the primary role of the browser's JavaScript engine?
Interpreting and executing JavaScript code
Defining the structure of a web page
Styling web page elements
Fetching data from a server
How do you access the value entered into a text input field in a form?
inputElement.getValue()
inputElement.data
inputElement.value
inputElement.text
Which of these is NOT a valid way to create a custom error in JavaScript?
throw 'This is a custom error'
throw { message: 'This is a custom error' }
throw new Error('This is a custom error')
throw new CustomError('This is a custom error')
Which keyword is used to declare a variable in JavaScript with block-level scope?
var
const
let
block
What is the purpose of the 'do-while' loop in JavaScript?
To execute a block of code only if a condition is true.
To declare a function.
To execute a block of code at least once, and then repeatedly as long as a condition is true.
To skip the current iteration of a loop.
What will the following code snippet log to the console?
console.log(5 + '5');
NaN
10
55
Error
Which property is used to set an attribute's value on an HTML element?
element.setAttribute('attributeName', 'value')
Both of the above
None of the above
element.attributeName = 'value'
What is the purpose of the return keyword in a function?
return
It assigns a value to a variable.
It specifies the data type of the function.
It sends a value back from the function to the caller.
It prints a value to the console.
Which event is fired when a user clicks on an HTML element?
onclick
onmouseover
onload
onmousedown