basic Flashcards
what is mostly use const or let?
const.
when should you use let?
when the value is going to change
playground to practice js?
jsbin.com
how do you write a normal js function ?
function myFunc() { }
assing an arrow function to a variable?
const myFunc = () => { }
what can you do with const process = (name) => { }?
remove parenthesis in the single argument
when you decalre a function in js do you have to declare the argument type?
no.
if your arrow function does not take arguments can you go const work = => {} ?
no you have to use const work = () => {}
if the body of your arrow function only has a return statement what can you do?
remove the {}. e,g,, const multiply (number) => number * 2;
even better const multiply number => number * 2;
what are default exports? and imports
when you export an object in your .js by saying at the end export default person
This makes the import for only the default, i.e.,
import prsn from ‘./person.js’
what are name imports? and exports
name exports: export const clean = () => {...} export const baseData = 10; notice there's no default keyword. the import has to go like: import {baseData } from './utility.js' or import {baseData, clean} from './utility'
others syntax’s allowed for import?
import {smth as Smth} from ‘./utility.js’
import * as bundled from ‘./utility.js’
create a class called Person in js
class Person { constructor() { this.name = 'Max'; }
printName() { console.log(this.name); } }
instanciate class Person and call method printName
const p = new Person(); p.printName();
create a class Human and make Person inherit from it
class Human { constructor() { this.gender = 'M'; printGender() { console.log(this.gender); } }
class Person extends Human { constructor() { super(); this.name = 'Max'; } printName() { console.log(this.Name); } }
what does ES6 means?
ECMA Script 6 (European Computer Manufacturers Association)
what is the official name of JavaScript?
ECMA Script
what is Babel?
is a transpiler, that does not compile but translate from one language to other. Babel translate from ES6 to normal Javascript
Es6 way to declare a class
class Person extends Human { name = 'Max';
printName = () => { console.log(this.name); } }
spread operator, how does it work?
const newArr = [ ... oldArr, 1, 2]; const newObj = { ... oldObj, newProp : 5 }
rest operator, how does it work? (pending)
const argSorter = (… args) => return args.sort();
what is the output difference between : const numbers = [1, 2, 3]; const newNumsA = [...numbers, 4]; and const newNumsB = [numbers, 4];
A gives [1, 2, 3, 4]
B gives [ [1, 2, 3], 4]
how do you create an object literal?
var person = {firstName:”John”, lastName:”Doe”, age:50, eyeColor:”blue”};
what does === means?
equality that checks for value and type
what is an array destruction? for example array [1, 2, 3] destroyed to the first two elements. (pending)
const numbers = [1, 2, 3]; [a, b] = numbers;
then you can use a as a var with value = 1 and b = 2
also you can do [a, , c] = numbers then c = 3
and what is object destructing?
same. e., g. const person = { name: 'Daniel', age: '8' ]; {name} = person; now name has 'Daniel'
value types in js
numbers, booleans and strings!
reference types in js?
arrays and objects
what is a superused way to use the spread operator?
expand
to copy reference types as value types, i.e., actual assigning a new pointer to the copy
array map function example
you get an array: const numbers = [1, 2,3]; then you say: numbersCopy = numbers.map( n => n * 2);
is an array map function a reference or a value copy?
a value copy
array function for filter,
arr.filter(c => c === 4);
what does a LTS version mean?
Long Term Support
how do you install environment to work on react?
npm intsall create-react-app -g
what is the name of the package for the build workflow?
create-react-app
what are the 3 dependencies added to a react project?
react, react-dom and react-scripts
what is the main html file of a react app?
index.html
what does the main html mainly contains?
a <div></div> which is where all the react magic will happen
how do you cover that javascript is not enabled, i.e., how do you tell the user to enable it?
You need to enable JavaScript to run this app.
what is manifest.json connected with?
progressive development of the application
what are the 4 scripts available in the build workflow?
start, test, build, eject, i.e., npm start, npm test, npm run build, npm run eject don’t use eject
what is the most important, i.e., entry point for a react app?
index.js. it has all the imports and it calls reactDOM.render() method.
how do you get the root element from the dom?
document.getElementById(‘root’)
get a random number (bet 0 and 1)?
Math.random()
get the integer part of a number?
Math.floor()