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.push('city', 'New York')
person['city'] = 'New York'
Object.assign(person, {city: 'New York'})
person.city = 'New York'
Which keyword is used to define an arrow function in JavaScript?
new
function
=>
arrow
What is the scope of a variable declared with 'var' inside a function?
Function scope
Block scope
Lexical scope
Global scope
What will be the output of the following code?
console.log(typeof null);
undefined
null
object
symbol
What is the purpose of event.preventDefault() in form handling?
event.preventDefault()
Validates the form data
Stops the form from submitting
Clears the form fields
Submits the form data asynchronously
How can you change the text content of an HTML element using JavaScript?
element.innerHTML = 'New text'
All of the above
element.innerText = 'New text'
element.textContent = 'New text'
Which method removes the first element from an array and returns it?
shift()
unshift()
pop()
slice()
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').src = 'new-image.jpg';
document.getElementById('profilePic').setAttribute('src', 'new-image.jpg');
document.querySelector('#profilePic').setAttribute('src', '/new-image.jpg');
What will be logged to the console?
function outer() { let x = 5; function inner() { console.log(x); } return inner; } const myFunc = outer(); myFunc();
5
ReferenceError
What is the value of 'x' after the following code is executed?
let x = 5; if (x > 10) { x = 10; } else { x = 0; }
0
10