Which method is NOT a built-in JavaScript array method?
find()
sort()
reverse()
length()
What will be logged to the console?
function outer() { let x = 5; function inner() { console.log(x); } return inner; } const myFunc = outer(); myFunc();
null
undefined
5
ReferenceError
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').textContent = 'Hello World!';
document.getElementById('myElement').innerText = 'Hello World!';
document.querySelector('#myElement').textContent = 'Hello World!';
What is the primary role of the browser's JavaScript engine?
Fetching data from a server
Interpreting and executing JavaScript code
Defining the structure of a web page
Styling web page elements
What value is returned by confirm('Are you sure?') if the user clicks the 'Cancel' button?
confirm('Are you sure?')
true
false
What is the purpose of event.preventDefault() in form handling?
event.preventDefault()
Validates the form data
Submits the form data asynchronously
Clears the form fields
Stops the form from submitting
What will the browser display after running this JavaScript code: alert('Hello') + ' World!'; ?
alert('Hello') + ' World!';
An error message
World!
Hello
Hello World!
Which of the following is NOT a feature of JavaScript?
Client-side scripting language
Object-oriented programming capabilities
Interpreted language
Strongly typed language
What is the output of the following JavaScript code: prompt('Enter your name:', 'John Doe');?
prompt('Enter your name:', 'John Doe');
It sets the user's name to 'John Doe' in the browser's local storage.
It displays a dialog box with the message 'Enter your name:' and a default input value 'John Doe', returning the user's input as a string.
It creates an alert box with the message 'Enter your name: John Doe'.
It prints 'Enter your name: John Doe' to the console.
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.