Front End Flashcards

1
Q

Inline vs inline-block

A

Inline-block allows us to set width and height as if the element was of block display. Inline elements don’t have this ability

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

What must an element have in order for margin: auto; to work?

A

It must have a set width

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

What is an element’s default position?

A

Static

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

If an element is given position: relative; what is it relative to?

A

Its default static position

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

What does confirm(“whatever”) return?

A

A boolean

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

What does prompt(“question”) return?

A

A string

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

What does alert(“message”) return?

A

nothing

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

If the script tag is in the head how do you make it work?

A

You add the keyword defer

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

How do you select the immediate p child of a div?

A

div > p this is called a child combinator

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

How do you select a p that is next to a div?

A

div + p this is called an adjacent sibling combinator

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

How do you select all even li?

A

li:nth-child(even)

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

What does git clean -xdf do?

A

Removes files not tracked by git (I think)

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

How do you select all p siblings of a div?

A

div ~ p General sibling combinator

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

How do you select list items with a class of “a” which are direct children of a <ul>?

A

ul > li[class=”a”]

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

What’s the difference between parseInt() and Number()?

A

parseInt() evaluates the argument upto the first non digit character in the string passed in. Number takes the whole argument and tries to convert that. Also parseInt takes the radix as the second argument

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

What are pseudo classes?

A

They are keywords added to a selector; ex. a:hover that specify a special state

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

What are attribute selectors?

A

They match elements based on the presence of value of a particular attribute; ex. a[href=”www.fava.com”]

18
Q

How do you place the cursor in vscode at the same point on three different lines vertically stacked?

A

option shift click

19
Q

What is the difference between container and container-fluid?

A

container-fluid continuously resizes, never leaving empty space. container will resize at certain points

20
Q

How do you use the content property in a css selector such as a:after?

A

It replaces an element with a generated value; ex.
a:before {
content: “⛅”;
}

21
Q

How do you store some value, say, string “count” to a num 5 in localStorage?

A

localStorage.setItem(“count”, 5);

22
Q

How can I read arguments passed to the program from node js?

A

process.argv
this returns an array
process.argv[2] returns the first argument
for instance
node app.js hello world would return ‘hello’

23
Q

What is fs?

A

It’s a library package for reading and writing files;
const fs = require(“fs”);
then you can use fs.readFile, fs.writeFile etc

24
Q

How do you create a Node.js project?

A

npm init -y

25
Q

What does npm init -y do?

A

It creates a Node.js project, it also creates a package.json file where the dependencies will be listed

26
Q

What happens when you install a package like npm i inquirer@^8.0.0?

A

The node_modules folder is created within the project and the package.json is moved into it. Another file, called package-lock.json, is also created inside this folder

27
Q

Describe inquirer.prompt()

A

inquirer.prompt() takes an array of objects, each object is a question. Each question has several optional properties: type, message and name, etc.
Ex:
inquirer.prompt([
{
type: “input”,
message: “what’s your name?”,
name: “username”
}
]

It returns a promise object so it’s thenable.
.then(response) is chained.
the response is an object that looks like this:
{username: “whatever you typed”}
In essence, the object will contain the properties referenced by name, in this case just “username”.

28
Q

What’s the difference between rest and spread operators?

A

the spread operator takes the contents of an array and spreads them in another array:

const a = [1,2,3];
const b = [3,4,5];
const c = […a, …b];
console.log(c); // [1,2,3,4,5,6]

the rest parameter syntax allows a function to accept any number of arguments as an array

29
Q

How could you define “state” in React?

A

A Component’s memory

30
Q

What two things need to happen in React to re-render a component?

A

a- Retain the data
b- Trigger a re-render

31
Q

What does the useState Hook provide?

A

A state variable and a state setter function

32
Q

What are componentDidMount() and componentWillUnmount() called?

A

Lifecycle methods

33
Q

How do you create a variable ‘root’ into which to insert React elements?

A

const root = ReactDOM.createRoot(document.getElementById(‘root’));

34
Q

How do you add <Clock></Clock> to ‘root’?

A

root.render(<Clock></Clock>);

35
Q

What does <Navlink> do under the hood?</Navlink>

A

1 - event.preventDefault() so that the page doesn’t redirect
2 - sets the state, which then causes a re render

36
Q

The path in the ‘to’ of the <Navlink> must be the same as?</Navlink>

A

The value of ‘path’ in the <Route>
ex.</Route>

<NavLink></Navlink>
<Route path="about" element={<About></About>} />
</NavLink>

37
Q

What is an alternative syntax to this:
<Route path=”/” element={<Home></Home>} /> ?

A

Warning: this may be deprecated

<Route>
<Home></Home>
</Route>

38
Q

What are the three steps when writing a test?

A

Arrange, act, assert

39
Q

What does this React shortcut do?
div.mb-3>label.form-label+input.form-control

A

It creates a div with the margin bottom of 3 (bootstrap class). Inside of it the label with form-label as class and next to that the input with form-control class

40
Q

What is a handy shortcut to check if an obj called errors has a name AND a type property?

A

errors.name?.type
this is called optional chaining

41
Q

Say ‘categories’ in this code:
<option></option>
{categories.map((category, index) => (
<option key={index} value={category}>
{category}
</option>
))}
isn’t yet imported, how do you do it quickly?

A

option and . while cursor is on ‘categories’

42
Q

What is z.enum() ?

A

One of many values. I imagine they are passed in as an array