Intro Stuff Flashcards

1
Q

What are common patterns for doing conditionals in XML?

A
  1. Ternary operator inline
  2. Use the ‘&&’ operator, when there’s no ‘else’ condition.
  3. Define a variable in an if/else above in the render() method, and then display that variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you take advantage of booleans in Javascript?

A

You can write variables and then set them equal to the condition. Then use the fact that that variable will be either truthy or falsey later on.

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

How do you loop in JSX?

A

Use array.map(fn)

class Messages extends React.Component {
   render(). {
      const msgs = [
           {id: 1, text: "Greetings!!"}, 
           {id: 2, text: "Goodbye!"}, 
      ];
      return (
          <ul>
            { msgs.map(m => <li>{m.text}</li>)  }
         </ul>
      );
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you make your JSX variables considerably shorter in your return statment?

A

Use destructuring.

class Friend extends Component {
  render() {
    const { name, hobbies } = this.props;
    return()
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does map work?

A

It returns the result of the callback function for each item in the array.

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

How do you put variables into a map return statement?

A

Put additional ‘{ }’ around the variables.

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

How do you handle events with state?

A
  1. Initialize state
    • Constructor
    • Super
    • Set ‘this.state’
  2. Use the state key inside of return function.
  3. Define a function inside the class that changes the state. handleClick(e)
  4. Add the function on the event handler inside of return
    • this.handleClick
  5. Bind ‘this’ inside the constructor
    • this.handleClick = this.handleClick.bind(this);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What things do you put inside the class?

A

Render
Default props
Constructor
event functions

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

What’s the shortcut for initializing state?

A

Leave the constructor out and just put something like this in the class:

state = {clicked: false};

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

What’s the shortcut for handling events and updating state?

A

Inside of the class call:

handleClick = e => {
this.setState({clicked: true});
};

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

Duplicate line up/down

A

Shift + Option + Up / Shift + Option + Down

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

Move Line up/down

A

Option + Up / Option + Down

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

Multi-select selection

A

Command + D (to select next occurrence(s) after you make an initial selection)

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

Multi-select Cursor

A

Option + Click

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

Toggle line comment

A

Command + /

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

Show/hide terminal

A

Control + ̀

17
Q

Add Line Comment

A

Command + K Command + C

18
Q

Toggle Sidebar

A

Command + B

19
Q

How do you choose a random pre-programmed value?

A

Put all the values into an Array, and then use the Math.floor(Math.random() *length of array) method and put it into the index of the array.

** You’ll end up choosing a random index inside the array that you’re using.