Useful Javascript methods Flashcards

Use this: https://nextjs.org/learn-pages-router/foundations/from-javascript-to-react/essential-javascript-react

1
Q

Using destructuring, load two variables, make and year, from the object car1.

Assume that car1 has properties with the same named variables.

A

const{make, year} = car1

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

Destructure an array ‘myArray’, placing the first two elements into variables var1 and var 2

A

const[var1, var2] = myArray

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

Inside a div, use a javascript method to take an array of objects named ‘skills’, and write out repeated set of components named ‘Skill’, which name property equal to the skillName property of each object in the array.

A

<div>{skills.map((skill) => <Skill name={skill.skillName}/>)}</div>

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

To a constant named result, assign the list of words from the array ‘words’ whose length is greater than 6.

A

const result = words.filter((word) => word.length > 6);

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

From an object array ‘cars’, put the first object into a new variable firstCar, and the remainder in a new array ‘remainingCards’.

A

const [firstCar, ...remainingCars] = cars;

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

Put the property ‘model’ of object ‘car1’ into a variable named ‘model’, and all the other properties of car1 into a new variable ‘otherInfo’

A

const {model, …otherInfo} = car1;

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

Define a new array ‘newCars’ by appending the object ‘car4’ on to the end of array ‘cars’.

A

const newCars = [...cars, car4];

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

Get some data from an API of url ‘myApiUrl’ and put it into an object named ‘data’

A

`
const result = await fetch(“https://myApiUrl”);
const data = await result.json();
`

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

Convert this code into an arrow function:
`
(function (a) {
return a + 100;
});
`

A

a => a + 100;

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

Convert this code into an arrow function:
~~~
(function (a, b) {
return a + b + 100;
});
~~~

A

() => a + b + 100;

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

Conver this function into an arrow function:
~~~
(function (a, b) {
const chuck = 42;
return a + b + chuck;
});
~~~

A
(a, b) => {
  const chuck = 42;
  return a + b + chuck;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define an immediately invoked, trad function, that has nothing but a comment as the function body.

A
(function() {
  /* */
})()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define an immediately invoked, arrow function, that has nothing but a comment as the function body.

A
(() => {
  /* */
})()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define an immediately invoked, arrow function, that returns ‘foobar’.

A

(() => "foobar")();

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

Define an arrow function entitled ‘simple’ that takes a parameter ‘a’, and returns 15 if ‘a’ is greater than 15, otherwise returns ‘a’.

A

const simple = (a) => (a > 15 ? 15 : a);

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