Which method is used to select an HTML element with a specific ID?
querySelector()
getElementById()
getElementbyId()
querySelectorAll()
How do you set the 'src' attribute of an image element with the ID 'profilePic' to 'new-image.jpg'?
document.querySelector('#profilePic').src = 'new-image.jpg';
document.getElementById('profilePic').setAttribute('src', 'new-image.jpg');
document.querySelector('#profilePic').setAttribute('src', '/new-image.jpg');
document.getElementById('profilePic').src = 'new-image.jpg';
What is the primary role of the browser's JavaScript engine?
Defining the structure of a web page
Interpreting and executing JavaScript code
Fetching data from a server
Styling web page elements
Which method removes the first element from an array and returns it?
slice()
pop()
unshift()
shift()
What is the purpose of the 'catch' block in a try...catch statement?
To execute code only if an error doesn't occur
To handle the error thrown in the 'try' block
To specify the type of error to catch
To re-throw the caught error
What is the scope of a variable declared inside a function in JavaScript?
Block scope
Function scope
Global scope
Local scope
Which keyword is used to define an arrow function in JavaScript?
function
arrow
=>
new
How can you change the text content of an HTML element using JavaScript?
element.textContent = 'New text'
All of the above
element.innerHTML = 'New text'
element.innerText = 'New text'
What is the role of 'server-side' JavaScript?
Creating animations and visual effects in the browser
Processing data and interacting with databases
Styling web pages with CSS
Handling user input on a web page
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
undefined