JavaScript from Zero to SuperheroChapter 61

Questions

Section 2 of 2-~ 12 min read-Synced from Cuantum content

Test your understanding of the fundamental concepts covered in the first part of "JavaScript from Scratch: Unlock your Web Development Superpowers" with this quiz. Each question is designed to reinforce the key points from each chapter, ensuring you have a solid grasp of the basics of JavaScript and DOM manipulation.

Question 1: Basic JavaScript

What is the output of the following JavaScript code?

console.log(typeof (typeof 1));

A) "string"

B) "number"

C) "object"

D) "boolean"

Question 2: Data Structures

Which method would you use to add an element to the beginning of an array? A) push()

B) pop()

C) shift()

D) unshift()

Question 3: JSON Handling

Which statement about JSON is correct? A) JSON is a programming language.

B) JSON strings must use single quotes.

C) JSON can include functions as values.

D) JSON is commonly used for data interchange between a server and web applications.

Question 4: DOM Manipulation

Which method is used to select an element by its ID? A) document.getElementByClassName()

B) document.getElementById()

C) document.querySelectorAll()

D) document.getElementsByTagName()

Question 5: Creating and Removing DOM Elements

What is the correct way to remove an element from the DOM? A) element.delete()

B) element.removeChild()

C) element.remove()

D) element.erase()

Question 6: Event Handling

What is the correct syntax to add an event listener that executes when a user clicks a button with the ID "submitBtn"?

document.querySelector('???').addEventListener('???', function() {    alert('Button clicked!');});

Fill in the '???' to correctly set up the event listener.

Question 7: Modifying Element Content

How do you change the text content of an element with the ID "header" to "Welcome to JavaScript"? A) document.getElementById('header').innerHTML = 'Welcome to JavaScript';

B) document.getElementById('header').textContent = 'Welcome to JavaScript';

C) document.getElementById('header').innerText = 'Welcome to JavaScript';

D) Both B and C are correct.

Question 8: Custom Events

True or False: Custom events can be used to trigger specific functionality that is not covered by native DOM events. A) True

B) False