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')
Object.assign(person, {city: 'New York'})
person.city = 'New York'
What is the difference between a function declaration and a function expression in JavaScript?
There is no difference; they are interchangeable.
Function declarations are hoisted, while function expressions are not.
Function expressions are hoisted, while function declarations are not.
Function declarations can only be anonymous.
How do you define default parameter values in a JavaScript function?
By using the 'defaults' keyword.
Using an if statement inside the function body.
By assigning values to parameters directly within the function definition.
Default parameters are not supported in JavaScript.
What will be the output of the following code?
console.log(typeof null);
null
undefined
symbol
object
What is the correct way to add an event listener that logs 'Button Clicked!' to the console when a button with the ID 'myButton' is clicked?
document.querySelector('#myButton').addEventListener('click', () => console.log('Button Clicked!'));
document.querySelector('#myButton').onclick = console.log('Button Clicked!');
document.getElementById('myButton').addEventListener('click', function() { console.log('Button Clicked!'); });
document.getElementById('myButton').addEventListener('click', console.log('Button Clicked!'));
let i = 0; while (i < 5) { console.log(i); i++; }
1 2 3 4 5
0 1 2 3 4 5
1 2 3 4
0 1 2 3 4
Why is JavaScript considered a 'dynamic' language?
It allows for the creation of visually appealing websites.
It enables changes to a webpage's content and behavior after it has loaded.
It is a very old programming language.
It enforces strict data types for variables.
Which block of code is executed regardless of whether an error is thrown or caught?
finally
throw
catch
try
Which of the following is NOT a built-in function in JavaScript for interacting with the user through the browser?
prompt()
console.log()
alert()
confirm()
What is the scope of a variable declared inside a function in JavaScript?
Function scope
Local scope
Global scope
Block scope