What is the correct way to add a new property 'city' with value 'New York' to the object person from the previous question?
person
person.city = 'New York'
person.push('city', 'New York')
person['city'] = 'New York'
Object.assign(person, {city: 'New York'})
Which keyword is used to declare a variable whose value should not change after its initial assignment?
const
static
var
let
What is the purpose of the return keyword in a function?
return
It prints a value to the console.
It specifies the data type of the function.
It sends a value back from the function to the caller.
It assigns a value to a variable.
What is the correct syntax to add an event listener to an element?
element.on('click', functionName)
element.addEventListener('click', functionName)
element.attachEvent('click', functionName)
element.addListener('click', functionName)
Which of the following is a valid way to define an arrow function that takes one parameter and returns its square?
const square = (x) => { x * x };
const square = x => x * x;
function square(x) { return x * x; }
let square = function(x) { return x * x }
What is the output of the following JavaScript code: prompt('Enter your name:', 'John Doe');?
prompt('Enter your name:', 'John Doe');
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 prints 'Enter your name: John Doe' to the console.
It sets the user's name to 'John Doe' in the browser's local storage.
It creates an alert box with the message 'Enter your name: John Doe'.
What is the role of 'server-side' JavaScript?
Processing data and interacting with databases
Styling web pages with CSS
Handling user input on a web page
Creating animations and visual effects in the browser
Which of the following is NOT a feature of JavaScript?
Strongly typed language
Interpreted language
Client-side scripting language
Object-oriented programming capabilities
Which method removes the first element from an array and returns it?
pop()
slice()
unshift()
shift()
Which block of code is executed regardless of whether an error is thrown or caught?
catch
try
throw
finally