The One Flashcards

(157 cards)

1
Q

What are 2 ways to check if there’s at least 1 ‘item’ of a certain thing exist in an array;

A
  • myArray.includes(item)
  • myArray.some(thing => thing === item)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to get what key is pressed on an keyboard event?

A
  • evt.key;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to create, in one line, a 2D array with x rows and y cols, using Array

A
  • const new2DArray = Array.from({ length: x }, () => new Array(y));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to toggle the ‘foo’ class on a given element?

A
  • element.classList.toggle("foo");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to select the sibling immediately before or immediately after an element using javascript?

A
  • const preElement = element.previousElementSibling;
  • const nextElement = element.nextElementSibling;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to assign bar into foo if bar is truthy, otherwise assign baz?

A
  • const foo = bar || baz
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to assign bar into foo if bar is not nullish (null or undefined), otherwise assign baz?

A
  • const foo = bar ?? baz
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to assign bar into foo if baz is truthy, otherwise assign baz?

A
  • const foo = baz && bar
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to insert an element right before, or right after an element? Without utilizing the parent element

A
  • node.insertAdjacentElement("beforebegin", nodeToInsert);
  • node.insertAdjacentElement("afterend", nodeToInsert);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the ‘every()’ method of Array take in as a parameter?

A
  • It takes in a function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is one way to check if all the elements in an array are the same?

A
  • myArray.every((val) => val === myArray[0]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s the difference between the ‘findIndex’ method and the ‘indexOf’ method of an array?

A
  • ‘IndexOf’ takes in an element as parameter
  • ‘findIndex’ takes in a function as parameter.
  • Both methods returns the index of the first element;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What data structure do you need to use for breathFirstSearch

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

How to write an async function that fetches some data?

A
  • const response = await fetch("<http://example.com>");
  • const data = await response.json();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 2 ways to iterate over a Set? given: const mySet = new Set([1,1,2,2,3]);

A
  • for(const item of mySet){}
  • mySet.forEach(item => {})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to clone a Set?

A
  • const newSet = new Set([...oldSet]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to get the list of children for a given node?

A
  • const children = element.children
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to get the bounding box of an element?

A
  • node.getBoundingClientRect();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to create, in one line, a 1D array with n items filled with ‘Infinity’?

A
  • const newArray = Array(n).fill(Infinity);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to get the X and Y mouse cursor position when an event happens?

A
  • event.clientX
  • event.clientY
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Given display: grid, what one CSS property results in a grid with 3 equal columns?

A
  • grid-template-columns: 1fr 1fr 1fr
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are the two ways to turn a Set into an array? given: const mySet = new Set([1,1,2,2,3]);

A
  • Array.from(mySet);
  • [...mySet]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to select the sibling of an element using javascript where the sibling has the id ‘foo’?

A
  • Array.from(element.parentNode.children).find(el => el.id === 'foo'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to remove all child of an element?

A
  • container.innerHTML = "";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Why might ```while (node.firstChild) node.removeChild(node.firstChild);``` be safer than just setting ```innerHTML = ""```
* `innerHTML=""` just wipes the DOM abruptly and can cause memory leak if associated listeners and states are NOT cleaned up. * `removeChild` is a little versatile and allows you to access and clean up each child before removal.
26
What form attribute is required to submit the form to an URL via POST?
* `
`
27
What are 2 ways to add a style attribute of width 10px to an existing element with Javascript?
* `element.setAttribute("style", "width:10px");` * `element.style.width = "10px";`
28
Given a `formElement`, how to get all the formData from this form as a single object?
* `const formData = new FormData(formElement);` * `const formValues = Object.fromEntries(formData.entries());`
29
Given a `formElement`, how to get all the formData from the form as tuples?
* `const formData = new FormData(formElement);` * `const formDataArray = Array.from(formData.entries());`
30
In CSS, how to target an element with class ‘.foo’, that is also an immediate sibling after an element with class ‘.bar’
* `.bar + .foo {...}`
31
In CSS, target an element with class ‘.foo’, that is a sibling after an element with class ‘.bar’. It doens’t have to be an immediate sibling.
* `.bar ~ .foo {}`
32
In CSS how to style an element with both .foo and .bar class?
* `.foo.bar{}`
33
In CSS, how to style an element with class .foo, that is a direct decendant of an element with class .bar
* `.bar > .foo{}`
34
In CSS, how to style all descendants of an element with class name ‘bar’, that has a class name ‘foo’
* `.bar .foo{}`
35
When display flex, with flex-direction as row what does ‘align-items: center’ do?
* Aligns items vertically - aka make the items with equal space above and below
36
When display flex, with flex-direction as column what does ‘align-items: center’ do?
* Aligns items horizontally - aka make the items with equal space left and right
37
How to duplicate an existing element before appending it to another element?
* `const clonedElement = existing.cloneNode(true);` * `// Pass true for a deep clone (to include child nodes)` * `targetContainer.appendChild(clonedElement);`
38
How to get the name attribute of an input element?
* `input.name`
39
How to remove all white spaces from a string?
* `value.replace(/\s/g, "")`
40
What properties should you pass into an iframe to overwrite default styling?
* `style=”border:none; overflow:hidden”` * `frameborder=”0” (Deprecated in HTML5)` * `scrolling=”no” (Deprecated in HTML5)` * `width/height`
41
What properties should you pass into an iframe to show the correct content?
* `src=”https://example.com”` * `title=”Title of the frame content”`
42
How to create a new Broadcast Channel and send a message?
* `const bc = new BroadcastChannel("internal_notification");` * `bc.postMessage("New listening connected")`
43
What is short polling?
* Where a client PERIODICALLY sends requests to a server at REGULAR intervals to check for updates.
44
What’s the call signature of ‘function.prototype.call()’ and ‘function.prototype apply()’?
* `call(thisArg, arg1, arg2, arg3...)` * `apply(thisAr, argArray)`
45
How to use query selector to select a div with role of timer?
* `document.querySelector("div[role='timer']")`
46
How to display a number that always at least takes up 3 digits eg: “012”, “004, “124”
* `num.toString().padStart(3, '0')`
47
How to set the disabled state of a button element with javascript?
* `button.disabled = true;` * `button.disabled = false;`
48
What function can be called recursively to tell the browser to generate an animation?
* `requestAnimationFrame(callback);`
49
How to stop an animation created by `requestAnimationFrame?`
* `cancelAnimationFrame(timerId);`
50
What aria tag links input to their error message?
* `` * `Where ‘error-message’ is an id`
51
What are the 3 main benefits of using WebP image format?
* Much smaller file size * Supports transparency like PNG * Support animation like GIF
52
What is the purpose of aria-live tags?
* To indicate an element is a live region and screen readers should announce updates automatically without the user needing to focus on it.
53
What are the two possible values for aria-live?
* polite: Announce updates when user finishes their current task. * assertive: Announce updates immediately.
54
What is the purpose of the defer attribute on a `