Which of the following is NOT a built-in function in JavaScript for interacting with the user through the browser?
confirm()
prompt()
alert()
console.log()
What is the purpose of the 'else if' statement in JavaScript?
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 declare a variable.
To provide an alternative block of code to execute if the preceding 'if' or 'else if' conditions are false.
What is the correct way to add an element 'apple' to the end of the array fruits = ['banana', 'orange']?
fruits = ['banana', 'orange']
fruits.push('apple')
fruits[2] = 'apple'
fruits = ['apple']
fruits.unshift('apple')
What will be the output of the following code?
let i = 0; while (i < 5) { console.log(i); i++; }
1 2 3 4
0 1 2 3 4 5
1 2 3 4 5
0 1 2 3 4
What is the value of 'x' after the following code is executed?
let x = 5; if (x > 10) { x = 10; } else { x = 0; }
5
10
0
undefined
Which of these is a valid way to embed JavaScript in an HTML file?
<js> alert('Hello!'); </js>
<javascript> alert('Hello!'); </javascript>
What is the correct syntax to add an event listener to an element?
element.addEventListener('click', functionName)
element.attachEvent('click', functionName)
element.on('click', functionName)
element.addListener('click', functionName)
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 will the following code snippet log to the console: console.log((function(x) { return x * 2; })(5));
console.log((function(x) { return x * 2; })(5));
ReferenceError
Which keyword is used to declare a variable whose value should not change after its initial assignment?
const
static
let
var