JS Flashcards

1
Q

save to local storage

A

localStorage.setItem(“key”, value)

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

convert from js object to JSON string

A

JSON.stringify(myObject)

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

get from local storage

A

localStorage.getItem(itemKey)

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

Flex

A

Container
display:flex
flex-direction: row/column row-reverse
justify-content: space-between
align-items: center, flex-start, flex-end, stretch

Items
flex-shrink
flex-grow
flex-basis

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

CSS descendant selectors

A

space, for example: ul.my-things li , List items that are descendants of the “my-things” list

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

General Sibling combinator selector

A

Tilde ~ selects all elements that are next siblings of a specified element
li.red ~ li , selects all the li’s that come after an li with a class of red

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

Select all elements that match various combinators (and)

A

just type them together without spaces

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

apply same css to different selectors (or)

A

separate them using commas

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

direct child selector

A

< , just the direct children

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

Css Adjacent Sibling Combinator

A

Selects only one sibling that comes after a selector
li.red + li, selects only the one li that comes after the li with the class of red

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

css pseudoclasses

A

hover, li:hover
:focus (buttons & form inputs when clicked)
:checked
:disabled
li:first-child

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

pseudo class to select the first child, last child, or n child, only child, first of type, last of type

A

li.red:first-child (only selects the first li if it has the class of red)
li:last-child
li:nth-child()
li:only-child (selects the li only if its the only child inside a block)
li:first-of-type (the first item of type li inside a block)
li:nth-of-type()
li:last-of-type

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

pseudo selector not

A

li:not(.green), pseudo selector that doesn’t have the class of green

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

pseudo elements

A

div.red::before, div.red::after Adds styling before or after de div with a class of red

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

Styling data attribute selectors. simple and with a particular value

A

[data-red]{ }

[data-red=”true”]{ }

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

attribute selector that matches the beginning

A

[data-red^=”12”]

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

attribute selector that matches the end

A

[data-red]$=”69”

<div></div>

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

Red data attribute selector that has 34 somewhere

A

<div></div>

[data-red]*=”34”

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

Adds a text to an element

A

element.innerText =”my new text” (visible content in a node)
or element.textContent= “My new text” (all content)

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

clone a template

A

const template = document.querySelector(“#myTemplate”)
const templateClone = template.content.cloneNode(true)

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

add a newElement to a listElement

A

listElement.appendChild(newElement)

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

check edge case inside a function where the input text is empty

A

if(inputText === ‘ ‘) return

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

add to an array

A

myArray.push(myText)

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

save to local storage, and what if saving an array value

A

localStorage.setItem(“keyName”, stringValue)

if the stringValue is an array
localStorage.setItem(“keyName”, JSON.stringify(stringValue))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
load from local storage
function loadItems(){ const storedItems = localStorage.getItems(KEY_NAME) return JSON.parse(storedItems) || [] // converts to js object or array }
26
event listener when we interact with a list
list.addEventListener("change",e=>{ e.target.matches("[data-checkbox-name]") })
27
create a unique value by milisecond
const uniqueValue = new Date().valueOf().toString()
28
add a data attribute 'todoId' in js to an element
element.dataSet.todoId = "123"
29
get the parent of a clicked item
e.target.closest('.parentName')
30
remove an element from the screen
element.remove()
31
get all the buttons dynamically
document.addEventListener('click', e => { if(!e.target.matches('.buttonClass')) return })
32
import node js modules
const myExportedThings = require(./user.js) console.log(myExportedThings.name) ---- file to export: module.exports{ name: name, age:age }
33
hide from the UI, mantain the element space
visibility:hidden/visible
34
hide from the UI, take no space
display:none/block
35
toggle a class called show in js
element.classList.toggle('show')
36
fire once a click event. (should be removed after clicking)
button.addEventListener('click',()=>{ //dostuff },{once:true})
37
create a button with js and give it the class of red, and attach it to a grid element
const myButton = document.createElement('button') myButton.classList.add("red") myGrid.appendChild(myButton)
38
Select all dataset with foo
Document.querySelectorAll("[data-foo]")
39
fetch request
fetch("URL") .then( response=>{return response.json() } .then( data=>{console.log(data)} )
40
classList functions
div.classList.add("foo") div.classList.remove("foo") div.classList.toggle("foo") div.classList.replace("foo", "bar")
41
convert string to integer
parseInt("3")
42
switch
switch(x){ case "oranges": break; case "apples": break; default; }
43
make a copy of an object
animal2= JSON.parse(JSON.stringify(animal))
44
agregar y quitar al final de un arreglo
myArray.push('red') myArray.pop()
45
quitar y poner en el frente de un arreglo
myArray.shift() myArray.unshift('red')
46
myArray.splice(2,1)
el index en el que queremos quitar, y el numero de elementos. Queremos quitar un elemento en el índice 2. Se modifica el arreglo
47
Var disadvantages
Breaks scope, has hoisting, allowed redeclaration
48
check if a variable is NaN
isNaN(variable)
49
constructor function
function User(name,age){ this.name = name this.age = age } const grace = new User(¨grace¨, 39)
50
class
class User(name,age) { constructor(){ this.name = name this.age = age } function sayName(){ console.log(this.name) } } const user1 = newUser("grace",28) user1.sayName()
51
code a select element
Red Green
52
html types
text, checkbox, radio, file, tel, url, hidden, color
53
Match a label with an input
The for with the id Color
54
whats a private variable
a variable only available in its own class starts with #, example #internalOnlyVariable and its not available to the children
55
whats a protected variable
a variable that cant be accessed outside of its class, but can be accessed by the children
56
event que se activa cuando escribes letra por letra en un input
input
57
event que se activa cuando escribes algo en un input y das clic afuera
change
58
Diferencia entre filter y find al filtrar un arreglo de objetos
Filter regresa un arreglo [{}], find regresa el objeto {}
59
Sets the active html element in the document. It can only be applied to one element
Document.querySelector('x').focus()
60
promises explain Promise.all new Promise.all([ Promise.resolve('1'), Promise.reject('error on 2'), Promise.resolve('3'), ]).then(messages=> console.log(messages)).catch(error=> console.error(error))
//logs the first to fail or an array with all the resolves ['1','2','3']
61
explain Promise.any
prints the first that succeeds. (only succeed not fail)
62
explain Promise.race
prints the first that succeeds or fails
63
explain Promise.allSettled
waits for all to finish and then gives the status of each[{status: rejected, reason: 'error on 1'}]
64
code a fetch using async await
async function fetchData(){ const response = await fetch('http') const data = await response.json() console.log(data.map(item => data.name)) }
65
post
fetch('http:///',{ headers: {"content-type":"application/json"}, body: JSON.stringify({ title: 'new post'}), method: POST, })
66
what are the 2 types of fetch requests
async or promise based
67