General Web Flashcards

1
Q

What is a semantic HTML tag and why might we want to use them?

A

A tag that describes what they are (header, footer, etc.). It makes reading code easier for ourselves and peers as well as being important for screen readers to make our site ADA accessible

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why do we need doctype at the beginning of an HTML document?

A

We want the browser to render HTML and XML in a standard format (HTML5).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Do document.onload and window.onload fire at the same time?

A

No, window.onload is fired when the entire page loads, including the contect, images, css, scripts, etc.

Document.onload is called when the DOM is ready, which can be prior to images and external content that needs to get loaded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the tag do?

A

Creates a dropdown that you can hide/unhide, it lets you put copyright information or metadata about your site. Click to expand and it will be unexpanded by default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Is there a difference between window and document?

A

Yes, the window is the first thing that gets loaded into the browser. It has the majority of object properties loaded onto it (length, inner-width, inner-height, name, if it’s been closed, etc.)

The document is one of the properties of the window object (HTML, PHP) and get’s loaded into the window object. Access document properties by using window.document.property or document.property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the different ways to get an element from DOM?

A

getElementById
getElementByClassName
getElementsByTagName (returns an HTML collection - no forEach)
querySelector
querySelectorAll (returns a node list - yes forEach)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would we implement getElementsByAttribute?

A

Save document.all to a variable, cast it to an array, iterate using for loop, and use .hasAttribute method, look for attribute ‘href’ and push all those nodes with the attribute into a result array.

Ex.
let b = document.all;
let result = [];
for (let node of b) {
	if (node.hasAttribute(‘href’)) {
		result.push(node)
	{
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do we add a class to an element using a query selector?

A
var list = document.querySelectorAll(“li”);
for (let i = 0; i < list.length; i++) {
	list[i].classList.add(‘something’);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How could I verify whether one element is a child of another?

A
function isDescendant(parent, child) {
	let node = child.parentNode;
        while (node != null) {
	        if (node == parent) {
		        return true;
	        }
	       node = node.parentNode;
       }
       return false;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are DocumentFragment ‘s?

A

Node objects which are never part of the main DOM tree. The normal use case is to create one and append elements to the document fragment and then append the document fragment to the “DOM tree. The fragment is then replaced by all its children.

It’s in memory but not part of th main DOM tree so appending children to it does not cause the page tor reflow, could result in better performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is repaint and when does this happend?

A

Repaint occurs when changes made to elements skin, changes it’s visibility, but not the layout. Includes outlining, visibility, background color

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is reflow? What causes reflow? How could you reduce reflow?

A

Reflow is critical in frontend performance, because it involves changes that affect the layout of a portion or whole webpage. A reflow of an element causes a subsequent reflow of all child/ancestor elements and elements following in the DOM. All other elements need to be repositioned to make room for the element we just moved around.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between event.target and event.currentTarget?

A

Target is the element that triggered the event and currentTarget is the element that the eventlistener is attached to.

Often can be the same, but in situations where bubbling up currentTarget changes on the way up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is event bubbling?

A

When an event happens on an element, it’ll first run the handlers on it, then it’s going to run on it’s parent, then it’s going to run up the ancestor chain up to the window.

ex. 3 nested elements: form > div > p with a handler on each of them. Clicking on p, will run onClick on p, then outer div, then outer form, then so on till outer document.

This can also happen in the opposite direction: capturing
Rarely used, but if you want to use it, you’ll have to add a third argument set to the addEventListener method

elem.addEventListener(“click”, e=> alert(‘capturing ${elem.tagName}’), true);

The event listener will be fired on click
The callback will be executed
But then, the true argument will tell the eventlistener to capture instead of bubble

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How could you capture all clicks in a page?

A

Put a clickhandler on the window

ex window.onClick

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How could you capture all the text in a web page?

A

document.body.innerText

17
Q

How could you destroy multiple list items with one click handler?

A

Leverage event bubbling by attaching an event handle to the parent element, for example a <ul> with 100 <li> items. When we click on a list item which doesn’t have an event listening, it bubbles up to the ul and fires the callback to grab the element and removeChild to remove from the dom.

document.getElementById('listToDestroy').addEventListener('click', function(e) {
     let el = e.target.parentNode;
     el.parentNode.removeChild(el);
     e.preventDefault();
}</li></ul>
18
Q

What is reflow?

A

Reflow is when the browser needs to recalculate the position/size of DOM elements in order to display a page. ie. insert, prepend, append, resizing scrolling etc.

In css display: none causes a reflow because it removed the element but visibility hidden doesn’t because the element is still taking up space on the DOM it’s just invisible.

19
Q

What is an AJAX request

A

Asynchronous Javascript and XML, that makes an HTTP request in the background, and when completed, we don’t load a new page like a normal HTTP request, instead, we fire a javascript callback.

JSON is the standard now, not XML.

20
Q

Whats is an HTTP request

A

The standard format to structure a request and response between a client and server. They indicate the specific action to be performed on a given resource.

21
Q

What is TCP

A

Transmission Control Protocol, manages the channels between browser and server.

22
Q

How to TCP and HTTP work together?

A

Typing a URL address in opens a TCP connection which then allows the client to make an HTTP request to the server. The URL allows us to get the IP address needed to connect to the server. Once the server sends the response, the TCP connection closes

23
Q

What are DOM Elements

A

Document - the root element on our page and entry point to the content in our page
Node - Basic element representing a node on the DOM
Element - Inherits from Node, all elements on document are descendent of Element
HTMLElement - Represents HTML elements created from an HTML tag
HTMLCollection - Array-like object containing a collection of HTMLElements

24
Q

What does Webpack do?

A

Compiles JS modules (module bundler) generating a single file that runs our app.