Next Generation Javascript Flashcards

(38 cards)

1
Q

Component?

A

Core building block of React

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

What is the Root of a React Component Tree

A

App

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

What does each Component need to return?

A

Each component needs to return / render some JSX code

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

What is JSX code?

A

It defines what HTML-like code React renders

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

What are the two types of React components?

A

Functional and Class Based

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

What is a Functional Component?

×

A

const cmp = ( ) => {return

some JSX
};

×

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

What is a Class-Based Component?

×

A

class cmp extends Component

Render ( ) {

Return

some JSX

;

}

};

×

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

What are Props?

A

Arguments passed to a component function

{props.title}

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

What are two ways of creating variables?

A

Let -> variable value

Const -> Variable that doesn’t change

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

What is an arrow function?

A

const myfunc = (arguments) => {function body}

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

How to write an arrow function with one argument?

A

const printMyName = name => console.log(name);

printMyName(‘Frank’);

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

An arrow function with two arguments

A

const printMyName = (name, age) => {

console.log(name, age);

}

printMyName(‘Frank’, ‘60’);

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

Arrow function shortcut if only returning one value

A

const mutliply = number => number*2;

console.log(multiply(2));

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

How to export a function

A

Export

person.js

const person = {name: ‘Max’};

export default person;

Import

import person from ‘./person’;

import prs from ‘./person’;

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

Export multiple functions

A

utility.js

Export

export const clean = () => { };

export const basedata= 10j;

Import

import {basedata} from ‘./utility’;

import {clean as cl} from ‘./utility’;

import * as bundled from ‘./utility’;

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

What is a class

A

A blueprint for an object

class person {

name= ‘Max’ PROPERTY

call = () => { }. METHOD

}

17
Q

How to instantiate a class?

A

class person {

name= ‘Max’ PROPERTY

call = () => { }. METHOD

}

const myPerson = new.Person

18
Q

What is inheritance

A

class Person extends Master

19
Q

super()

A

if you extend a class you must call ‘super’ to initiate the parent class when instantiating a new child class

20
Q

What is a spread operator?

A

Used to split up array elements or object properties

const newArray = […oldArray, 1,2]

const newObject = {…oldObject, newproperty:5};

21
Q

What is a rest operator?

A

Used to merge a list of function arguments into an array

function sortArgs(…args) {

return args.sort()

}

22
Q

What is destructuring?

A

Easily extracts array elements or object properties and stores them in variables

Array[a,b] = [‘Hello’,’Max’]

Object {name} = {name=’Max’, age: 28}

23
Q

What are primitive types?

A

Actual value is copied

numbers, strings, booleans

24
Q

What are reference types?

A

A pointer is copied

objects, arrays

to actually make a copy of the object or array use a spread operator

const secondPerson = {

…Person

};

25
Array functions - map
const numbers = [1,2,3]; const doubleNumbers = numbers.map((num) =\> return num\*2; };
26
What are the 8 data types in javascript?
Number - of any kind BigInt - Integers of arbitrary length String - zero or more characters Boolean - True or False Null - Fir unknown values Undefined - For unassigned values Object - For more complex data structures Symbol - For unique identifiers
27
JS Array Functions
map() find() findIndex() filter() reduce() concat() slice() splice()
28
JS Array Functions - find()
The find() method returns the value of the first element in the provided array that satisfies the testing function const array1 = [5,12,8,130,44]; const found = array1.find(element=\> element\>10); console.log(found); ANS: 12
29
JS Array Functions - findIndex()
The findIndex() method returns the index of the first element in the array that satisfies the provided testing function const array1 = [5,12,8,130,44]; const isLargeNumber = (element) =\> element\>13; console.log(array1.findIndex(isLargeNumber); ANS: 13
30
JS Array Functions - filter()
The filter() method creates a new array with all elements that pass the test implemented by the provided function const words=['spray','limit','elite','exhuberant','destruction','present'}; const result=words.filter(word=\>word.length\>6); console.log(result); ANS: array['exhuberant','destruction','present'};
31
JS Array Functions - reduce()
The reduce() method executes a reducer function (that you provide) on each element of the array resulting in a single output value const array1=[1,2,3,4}; const reducer= (accumulator, current value) =\> accumulator + current value; console. log(array1.reduce(reducer); ANS: 10 console. log(array1.reduce(reducer,5); ANS: 5
32
JS Array Function - concat()
The concat() method is used to merge two or more arrays. This method doesn't change the existing arrays, but instead returns a new array const array1=['A','B','C'}; const array2=['D','E','F'}; const array3=array1.concat(array2); console.log(array3); ANS: array['A','B','C','D','E','F'];
33
JS Array Functions - slice()
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in the array const animals=['ant','bison','camels','duck','elephant']; console. log(animals.slice(2)); ANS array['camels','duck','elephant']; console. log(animales.slice(2,4)); ANS array['camels','duck']; console. log(animales.slice(1,5)); ANS array['bison','camels','duck','elephant'];];
34
JS Array Function - splice()
The splice() function changes the contents of an array by removing or replacing existing elements and / or adding new elements const months=['jan','mar','apr','jun',]; months. splice(1,0,'feb'); ANS: inserts at index 1 console. log(months); ANS array['jan','feb','mar','apr','jun',]; months. splic(4,1,'may'); ANS replaces 1 element at index 4 console. log(months) ANS array['jan','feb','mar','apr','may',];
35
What is a component
a core building block of React
36
Component Tree
Root =\> 'App'
37
What is JSX
Each component needs to return / render some jsx code --\> it defines what HTML code react renders
38
Getting started
install node.js then install react sudo npm install create-react-app -g create-react-app name-of-your-app --scripts-version 1.1.5