Next Generation Javascript Flashcards
(38 cards)
Component?
Core building block of React
What is the Root of a React Component Tree
App
What does each Component need to return?
Each component needs to return / render some JSX code
What is JSX code?
It defines what HTML-like code React renders
What are the two types of React components?
Functional and Class Based
What is a Functional Component?
×
const cmp = ( ) => {return
some JSX
};
×
What is a Class-Based Component?
×
class cmp extends Component
Render ( ) {
Return
some JSX
;
}
};
×
What are Props?
Arguments passed to a component function
{props.title}
What are two ways of creating variables?
Let -> variable value
Const -> Variable that doesn’t change
What is an arrow function?
const myfunc = (arguments) => {function body}
How to write an arrow function with one argument?
const printMyName = name => console.log(name);
printMyName(‘Frank’);
An arrow function with two arguments
const printMyName = (name, age) => {
console.log(name, age);
}
printMyName(‘Frank’, ‘60’);
Arrow function shortcut if only returning one value
const mutliply = number => number*2;
console.log(multiply(2));
How to export a function
Export
person.js
const person = {name: ‘Max’};
export default person;
Import
import person from ‘./person’;
import prs from ‘./person’;
Export multiple functions
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’;
What is a class
A blueprint for an object
class person {
name= ‘Max’ PROPERTY
call = () => { }. METHOD
}
How to instantiate a class?
class person {
name= ‘Max’ PROPERTY
call = () => { }. METHOD
}
const myPerson = new.Person
What is inheritance
class Person extends Master
super()
if you extend a class you must call ‘super’ to initiate the parent class when instantiating a new child class
What is a spread operator?
Used to split up array elements or object properties
const newArray = […oldArray, 1,2]
const newObject = {…oldObject, newproperty:5};
What is a rest operator?
Used to merge a list of function arguments into an array
function sortArgs(…args) {
return args.sort()
}
What is destructuring?
Easily extracts array elements or object properties and stores them in variables
Array[a,b] = [‘Hello’,’Max’]
Object {name} = {name=’Max’, age: 28}
What are primitive types?
Actual value is copied
numbers, strings, booleans
What are reference types?
A pointer is copied
objects, arrays
to actually make a copy of the object or array use a spread operator
const secondPerson = {
…Person
};