Cis 2336 Midterm 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the difference between the <p> and the <div> element? In what contexts should one use one over the other?

<p> is for paragraphs and <div> is for divisions in HTML, use <p> for text and <div> for layout

When working with the Document Object Model (DOM) in web development, what is a key difference between interacting with a DOM Node and interacting with a NodeList?

A DOM Node represents a single element or component of a web page, while a NodeList is an array-like collection of nodes that can be iterated over.

What are the main benefits of using CSS?

Allows for better printing of web pages. Enables multiple pages to share formatting and reduces complexity in the HTML file. Speeds up website loading time.

Where is the correct place to insert a JavaScript in HTML file?

Both the <head> section and the <body> section are correct

Which statement best describes the difference between the event capturing phase and the event bubbling phase in the context of JavaScript events?

Capturing moves from the window to the target (downwards), while bubbling moves from the target to the window (upwards).

What does the following constant declaration signify in JavaScript? const taxRate = () => 0.05;

Declares a constant named taxRate as a function that, when called, returns the value 0.05.

What are HTML elements? What are HTML attributes?

Elements are the building blocks of HTML and attributes provide additional information about elements.

What are the key differences between HTTP GET and POST methods?

GET sends data appended to the URL, is less secure, and is mainly used for retrieving data, while POST sends data in the request body, is more secure, and is used for updating data.

How is Git different than GitHub?

Git is a distributed version control system that allows for local repository management, while GitHub is an online platform that provides cloud storage for Git repositories.

Consider the following JavaScript code snippet, what is the value of result after the code is executed? function outerFunction(outerVariable) { return function innerFunction(innerVariable) { return outerVariable + innerVariable; }; } const newFunction = outerFunction('Hello, '); const result = newFunction('World');

Hello, World!

Why is removing presentation-oriented markup from one's HTML documents considered to be a best practice? Where is the proper place to locate presentation/formatting?

It separates content from design, enhancing maintainability; the proper place is in CSS files.

Given the following while loop in JavaScript, what will it do? let i = 5; while (i > 0) { console.log(i); i--; }

It will log the numbers 5 to 1 to the console.

What is the scope of a variable declared with var inside a function in JavaScript?

Local scope / Function scope

What will bar be equal to after executing the following JavaScript code? function foo(a,b) { return a+b; } let bar = foo(3);

NaN

Where should input validation be performed in web application development?

On both the client and server sides

What is a regular expression, and what are its primary uses? Select ALL that apply.

Regular expressions can be utilized to perform complex replacements in text, such as formatting phone numbers or converting dates to a different format. They are used for validating input data, such as checking if an email address or phone number is in a correct format. A regular expression is a sequence of characters that forms a search pattern, used for finding or matching text in strings.

What are the different parts of a CSS style rule?

Selector, property, and value

In the context of JavaScript event handling, under which scenario would it be appropriate to stop event bubbling and to utilize bubbling?

Stop bubbling when you want to prevent an event from reaching ancestor elements; use bubbling to handle events at a common ancestor instead of at each descendant.

What is the purpose of the "action" attribute in an HTML form?

The "action" attribute specifies the URL of the server page that will process the form data when the form is submitted.

Given the JavaScript code snippet below, which statement accurately describes the operations performed on DOM elements? const headerElement = document.getElementById("header"); const listItems = document.getElementsByClassName("list-item"); headerElement.style.color = "blue"; const firstItemText = listItems[0].innerText;

The code accesses a single element by its ID "header" and changes its text color to blue, then it reads the inner text of the first element with the class name "list-item".

In which scenarios would calling preventDefault on a form submission event be appropriate? Select ALL that apply.

To temporarily disable form submission while waiting for an asynchronous operation, like an API call, to complete. When you want to validate the form data on the client-side before allowing the form to be submitted to the server.

In what situations would you use a radio button and a checkbox?

Use a radio button when only one option needs to be selected from a list, and a checkbox when multiple options can be selected.

When dynamically updating the content of a web page using JavaScript, what are the best practices regarding the use of innerHTML, textContent, and direct DOM manipulation methods like appendChild() or createElement()?

Using innerHTML is discouraged due to potential security risks, such as cross-site scripting (XSS) attacks, whereas textContent is safer for changing just the text content, and DOM manipulation methods are recommended for creating and managing HTML elements.

What best describes the Document Object Model (DOM) in web application development?

a programming interface that allows scripts to update the content, structure, and style of a document dynamically.

Fill in the missing line in the JavaScript code below to correctly register an event listener that shows an alert when the button with the ID "myButton" is clicked. // HTML for the button// <button id="myButton">Click me!</button> // Below please fill in the JavaScript code to handle the button click event:

document.getElementById("myButton").addEventListener("click", function() { alert("Button was clicked!"); });

Which of the following are valid JavaScript event types? Select ALL that apply.

keydown' 'click' 'mouseover'

Which of these are valid ways to declare a variable in JavaScript?

let number; const number;

Which of the following is the correct way to parse a JSON string into a JavaScript object?

let obj = JSON.parse(jsonString);

What is the difference between let and const in JavaScript?

let variables can be reassigned, but const variables cannot.

Which of the following methods can be used to display a message in a modal window in JavaScript?

window.alert("message");


Ensembles d'études connexes

Chapter 13: Practicing Evidence-Based Decision Making

View Set