Programing Flashcards

typescirpt, javascript, webpack ,react (99 cards)

1
Q

Immediately Invoked Function Expression (IIFE)

(() => console.log(‘Hello world’))();

A

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

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

Abstraction

A

Abstraction in computer programming is a way to reduce complexity and allow efficient design and implementation in complex software systems. It hides the technical complexity of systems behind simpler APIs.

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

Accessibility

A

Web Accessibility (A11Y) refers to best practices for keeping a website usable despite physical and technical restrictions.

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

Execution context

A

Created to run the code of a
function - has 2 parts
- Thread of execution
- Memory

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

Call stack

A

JavaScript keeps track of what
function is currently running
(where’s the thread of execution)
- Run a function - add to call stack
- Finish running the function - JS
removes it from call stack
- Whatever is top of the call stack
- that’s the function we’re
currently running

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

thread
of execution

A

Goes through the code
line-by-line and runs/ ’executes’
each line - known as the thread
of execution

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

string.trim()

A

`var myString = ‘ Some Tabs and Spaces ‘;
console.log(myString.length); // logs 28
var myNewString = myString.trim(); // trim it
console.log(myNewString); // logs ‘Some Tabs and Spaces’
console.log(myNewString.length); // logs 20

// Note: this method does not mutate a value it creates a new value
console.log(myString, myString.length); // This still is, ‘ Some Tabs and Spaces ‘

The ES5 .trim() method removes whitespace from both ends

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

Array.isArray()

A

The Array.isArray() method is used to determine precisely (true or false) if a value is a true Array. In other words, this method checks to see if the provided value is an instance of the Array() constructor.

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

[].some()

A

The [].some() method will start testing values in array, until a test returns true, then the function passed to .some() immediately returns true, otherwise the function returns false (i.e. the first truthy value found will result in the function immediately returning true and potentially this could mean not all tests are run).

~~~
// Check if one or more items in the array is bigger than or equal to 2
var someMethod = [1, 2, 3].some(function(value, valueIndex, wholeArray){
return value >= 2;
});

console.log(someMethod)
// logs true because the array contains a value that is greater than or equal to 2
```

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

[].every()

A

The [].every() method will start testing values in array, until a test returns false, then the function passed to .every() immediately returns false, otherwise the function returns true (i.e. the first falsy value found will result in the function immediately returning false and potentially this could mean not all tests are run).

// Check if every item in the array is bigger than or equal to 2
var everyMethod = [1, 2, 3].every(function(value, valueIndex, wholeArray){
    return value >= 2;
});

console.log(everyMethod) // logs false because the array contains a value that is less than 2
    
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

[].filter()

A

[].filter() method will return a new Array containing all the values tha (i.e. are true) the filtering test.

```var myArray = [1,2,3];
// filter out any value in the array that is not bigger than or equal to 2
var FilteredArray = myArray.filter(function(value, valueIndex, wholeArray){
return value >= 2;
});

console.log(FilteredArray) // logs [2,3]

// Note: filter() returns a new Array, myArray is still equal to [1,2,3]```

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

[].forEach()

A

The [].forEach() method executes a provided function for each value in the array.

// log to the console each value, valueIndex, and wholeArray passed to the function
['dog','cat','mouse'].forEach(function(value, valueIndex, wholeArray){
    console.log('value = '+value+' valueIndex = '+valueIndex+' wholeArray = '+wholeArray);
    /** logs:

    "value=dog valueIndex=0 wholeArray=dog,cat,mouse "
    "value=cat valueIndex=1 wholeArray=dog,cat,mouse "
    "value=mouse valueIndex=2 wholeArray=dog,cat,mouse "

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

[].indexOf()

A

The [].indexOf() method searches an array for the first value matching the value passed to indexOf(), and returns the index of this value.

// get index of first 'cat'
console.log(['dog','cat','mouse', 'cat'].indexOf('cat')); // logs 1

// Note: Remember the index starts at 0
    
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

[].lastIndexOf()

A

The [].lastIndexOf() method searches an array for the last value matching the value passed to [].lastIndexOf(), and returns the index of this value.

// get index of last 'cat'
console.log(['dog','cat','mouse', 'cat'].lastIndexOf('cat')); // logs 3

// Note: Remember the index starts at 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

[].map()

A

The [].map() method executes a provided function for each value in the array, and returns the results in a new array.

var myArray = [5, 15, 25];
// add 10 to every number in the array
var mappedArray = myArray.map(function(value, valueIndex, wholeArray){
    return value + 10;
});

console.log(mappedArray) // logs [15,25,35]

// Note: map() returns a new Array, myArray is still equal to [5, 15, 25]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

[].reduce()

A

The [].reduce() method runs a function that passes the return value to the next iteration of the function using values in the array from left to right and returning a final value.

// add up numbers in array from left to right i.e. (((5+5) +5 ) + 2)
var reduceMethod = [5, 5, 5, 2].reduce(function(accumulator, value, valueIndex, wholeArray){
    return accumulator + value;
});
console.log(reduceMethod) // logs 17

/** reduce also accepts a second parameter that sets the first accumulator value,
instead of using the first value in the array. **/

// add up numbers in array from left to right, but start at 10 i.e. ((((10+5) +5 ) +5 ) + 2)
var reduceMethod = [5, 5, 5, 2].reduce(function(accumulator, value, valueIndex, wholeArray){
    return accumulator + value; // first iteration of func accumulator is 10 not 5
}, 10);
console.log(reduceMethod) // logs 27
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The [].reduceRight() method runs a function that passes the return value to the next iteration of the function using values in the array from right to left and returning a final value.

A

The [].reduceRight() method runs a function that passes the return value to the next iteration of the function using values in the array from right to left and returning a final value.

// add up numbers in array from left to right i.e. (((2+5) +5 ) + 5)
var reduceRightMethod = [5, 5, 5, 2].reduceRight(function(accumulator, value, valueIndex, wholeArray){
    return accumulator + value;
});
console.log(reduceRightMethod) // logs 17

/** reduce also accepts a second parameter that sets the first accumulator value,
instead of using the first value in the array. **/

// add up numbers in array from left to right, but start at 10 i.e. ((((10+2) + 5 ) +5 ) + 5)
var reduceRightMethod = [5, 5, 5, 2].reduceRight(function(accumulator, value, valueIndex, wholeArray){
    return accumulator + value; // first iteration of func accumulator is 10 not 5
}, 10);
console.log(reduceRightMethod) // logs 27
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

New ES5 Getters and Setters (aka Accessors Descriptors or Computed Properties)

A

ES5 adds to Objects computed properties via the keywords get and set. This means that Objects can have properties, that are methods, but don’t act like methods (i.e you don’t invoke them using ()). In short by labeling a function in an object with get or set one can invoke the backing property function on a property, by merely accessing the property, without using innovating brackets.

The example below demonstrates the nature of getter and setter properties:

var person = {
    firstName : '',
    lastName : '',
    get name() {
        return this.firstName + ' ' + this.lastName;
    },
    set name(str) {
        var n = str.split(/\s+/);
        this.firstName = n.shift();
        this.lastName = n.join(' ');
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Object.create()

A

ES5 added the Object.create() method so objects could be created and their prototypes easily setup. Object.getPrototypeOf() was added to easily get an objects prototype.

// setup an object to be used as the prototype to a newly created myObject object below
var aPrototype = {
    foo: 'bar',
    getFoo: function(){
        console.log(this.foo);
    }
}

// create a new myObject, setting the prototype of this new object to aPrototype
var myObject = Object.create(aPrototype);

// logs 'bar' because myObject uses aPrototype as its prototype, it inherits getFoo()
myObject.getFoo(); // logs 'bar'

// get a reference to the prototype of myObject, using getPrototypeOf()
console.log(Object.getPrototypeOf(myObject) === aPrototype); //logs true
    
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Object.defineProperty()

A

ES5 added Object.defineProperty(), Object.defineProperties(), and Object.getOwnPropertyDescriptor() so object properties can be precisely defined (using descriptors) and retrieved. Descriptors provide an attribute that describe a property in an object. The attributes (i.e descriptors) that each property can have are: configurable, enumerable, value, writable, get, and set.

// add a property, 'value2' with descriptors to myObject using Object.defineProperty()
Object.defineProperty(myObject, 'prop2', {
    value: 'value2',
    writable: true,
    enumerable: true,
    configurable: true,
});

// get the descriptors for the prop2 property.
console.log(Object.getOwnPropertyDescriptor(myObject,'prop2'));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Object.keys()

A

ES5 added Object.keys() which returns an Array of non-inherited-enumerable properties of a given object. ES5 added Object.getOwnPropertyNames() which returns an Array of non-inherited properties of a given object regardless of enumerability.

~~~
// Create an object
var myObject = Object.create(null); // no prototype used

// Add prop to object created
myObject.myObjectProp1 = 1;

// Define a property using defineProperty()
Object.defineProperty(myObject, ‘myObjectProp2’, {
enumerable: false,
value: 2
});

// Use keys() to get Array of all non-inherited, enumerable properties
console.log(Object.keys(myObject)); // logs [“myObjectProp1”]

// Use getOwnPropertyNames to get Array of all non-inherited properties including non-enumerable
console.log(Object.getOwnPropertyNames(myObject)); // logs [“myObjectProp1”, “myObjectProp2”]
```

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

Object.preventExtensions()

A

Stops properties from being added but not deleted.

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

Object.seal():

A

Stops properties from being added or configured (i.e. the configurable descriptor attribute for each property is changed to false).

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

Object.freeze()

A

Stops properties from being added, configured, or writable (i.e. the configurable and writable descriptor attribute for each property is changed to false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Object.isExtensible():
Boolean check if an object is extensible.
26
Object.isSealed()
Boolean checking if an object is sealed.
27
Object.isFrozen()
Boolean checking if an object is frozen.
28
29
Thread of Execution
Story of the code execution, line by line
30
Function
Block of code that referance is saved in memory
31
Call Stack
Data structure working as LIFO where the active functions are stored and didn't finish their work, its go one by one.
32
Higher Order Function
Functions that takes another function or returning a function
33
Arrow Functions
ES6 arrow function make a this asign to the context where was defined
34
Clousure
Its like a backpack with required data that are passed to function even if execution context are done you can still have acces to nesecery data. Its a function with all data from lexical scope
35
Task
SetTimeout, SetInterval, task are last to go | Thread of Execution > MicroTask > Task
36
MicroTask
Fetch, micro task are priorytaized before tasks but after Global Thread of Execution | Thread of Execution > MicroTask > Task
37
Promises
Promise create a empty object with a promision some data will be passed in, we can use those data after using then or catch a error
38
Class
ES6 Class simplify creating a Object
39
Object.create()
Object.create create a empty object but pass a "__proto__" as a hidden property
40
Increment/Preincrement
``` x=40 x++//40 x//41 ++x//42 ```
41
++
At fist take value make is a Number then add a 1
42
Primitive Types
undefind, null, string, number, bigint, bolean, symbol,
43
In JavaScript, everything is an object.
False, but most of things can beehive like a object
44
In JavaScript, variables don't have types, values do.
45
typeof
Return a type of value stored in variable
46
NaN is only value that is no equal to themselfs
NaN === NaN // false
47
NaN: Invalid Number NaN is always a Number
48
Negative Zero
var trendRate = -0; trendRate === -0; // true trendRate.toString(); // "0" trendRate === 0; // true trendRate < 0; // true trendRate > 0; // false Object.is(trendRate, -0); // true Object.is(trendRate, 0); // false
49
Math.sign()
check the sign of number return 5 values | 1, -1, 0, -0, NaN
50
Fundamental Objects | Built-In Objects or Native Functions
51
Use New: 1. Object() 2. Array() 3. Function() 4. Date() 5. RegExp() 6. Error()
Dont use new: 1. String() 2. Number() 3. Boolean()
52
Coercion
Automaticly changing value to a string or number if needed ``` let result = '3' + 2; // '32', number 2 is converted to a string let num = Number('123'); // Converts string '123' to number 123 ```
53
using double !!
! sign make a Coercion to bolean, double !! can make from !!0 = false
54
Boolean()
Transform value to boolean
55
Boxing
Boxing in JavaScript is the automatic conversion of primitive types to their corresponding object types to access methods and properties.
56
Number(''), Number(' \t\n'), Number(null), Number(undefined), Number([]), Number([1,2,3]), Number([null]), Number([undefined]), Number({}),
Number(''), //0 Number(' \t\n'), //0 Number(null), //0 Number(undefined), //NaN Number([]), //0 Number([1,2,3]), //NaN Number([null]), //0 Number([undefined]), //0 Number({}), //0
57
String(-0), String(null), String(undefined), String([null]), String([undefined]), String(false),
String(-0), //"0" String(null), // 'null' String(undefined), //'undefined' String([null]), // '' String([undefined]), // '' String(false), // ''
58
Boolean(new Boolean(false))
true
59
Boolean
Its asking if its on falsy list false - The boolean false value. 0 - The number zero. -0 - The negative zero. 0n - BigInt, representing zero. "" - Empty string value. null - Denotes a null value. undefined - Indicates an undefined value. NaN - Represents "Not-a-Number".
60
1 < 2 < 3 = true but...
1 < 2 = true true = 1 1 < 3
61
3 > 2 > 1 = false
3 > 2 = true tru = 1 1 > 1 False
62
make a uniq array
``` let newArray = [...new Set(array1.concat(array2))]; // Merge and remove duplicates ```
63
== When the type match do the ===
64
Dont use == with
== with 0 , '', ' ' == with non-primitves ==true or == false allow ===
65
use == only if u know a types
66
console.log(undefined == null)//true
67
Lexical Scope
Lexical Scopes tell us where we can find our functions and varibales
68
JavaScript organizes scopes with functions and blocks
69
Shadowing
Its happend if variable in inner scope have the same name as a variable in outer scope
70
TypeError
When you try to do smth with incorect type
71
auto global
When a variable is assigned a value without being declared with var, let, or const within a function or a block, JavaScript will automatically create a global variable if it doesn't find the variable already declared in the global scope | Only in non-strict mode
72
ReferenceError
"ReferenceError występuje, gdy próbujemy odwołać się do czegoś, co nie zostało zadeklarowane."
73
Function declaration vs Function Expresion
You have always acces to function declaration even before a declaration cuz of hoisting, funtion expresion on other hand don't have a hoisng mechanizm so you have only acces to this function after declaration the variable
74
Named Function Expressions
We giving our function expression a name | const getName = function getMyName() { console.log('Kamil') }
75
call()
call help to invoke function with passed context as argument function sayHello() { console.log("Cześć, jestem " + this.name); } var dog = { name: "Piesek", }; var cat = { name: "Kotek", }; // Użycie magii "Call": sayHello.call(dog); // Magicznie sprawiasz, że Piesek mówi za siebie. sayHello.call(cat); // Magicznie sprawiasz, że Piesek mówi głosem Kotka.
76
explicit binding
Explicit binding is a powerful feature in JavaScript that provides flexibility in how functions are called and applied.
77
hard binding
Ensures that a function always executes with the specified this context, effectively "locking in" the function's execution context ahead of time.
78
new: steps
1. Create a brand new empty object 2. Link that object to another object 3. Call function with this set to thenew object 4. if function doesnot return an object, assume return of this
79
this in arrow function
this in arrow function works like in lexical scope
80
Object is not a scope
81
Super
Super is a reference to parent class
82
Co to jest useState w React?
useState to hook umożliwiający komponentom funkcyjnym przechowywanie i manipulowanie stanem wewnętrznym. Jest wywoływany z wartością początkową stanu i zwraca parę: aktualną wartość stanu oraz funkcję do jego aktualizacji. Umożliwia on komponentom reagowanie na zmiany danych i jest podstawą budowania interaktywnych interfejsów użytkownika. Przykład użycia: ```js const [count, setCount] = useState(0);
83
What is the Link component in React Router and how is it used?
84
BrowserRouter
BrowserRouter is a React Router component that uses the HTML5 history API to keep your UI in sync with the URL. It listens to changes in the URL and updates the page content accordingly without reloading the page. It's suitable for dynamic web applications where the URL in the browser's address bar should reflect the current page content and be bookmarkable. It wraps the application's routing structure.
85
Routes
The Routes component is a container for all individual Route components in a React application. It replaces the Switch component used in previous versions of React Router. It's responsible for selecting which route to render based on the current URL. Only the first child Route that matches the current location gets rendered, making it more efficient and straightforward for conditional rendering based on the path.
86
How does the Route component work in React Router?
The Route component is used to define a mapping between a URL path and a component in a React application. It renders the associated component when the application's URL matches its path prop. Routes are typically wrapped within a Routes component to ensure that only one route is rendered at a time. Syntax example: } />
87
UseState
88
UseRef
89
DOM
Document Model Object connect the web pages to JavaScript by representing the structrue of a document in memory
90
DOM API
A browser API expose for developer to maintance the DOM from scripting language
91
popstate
Event listener that listen for change url in same page navigation
92
history.pushState
Allows for use to manipulate urls without reload the page
93
substring
94
new Proxy w JavaScript
new Proxy to funkcja w JavaScript, która tworzy specjalny obiekt, działający jako pośrednik między tobą a innym obiektem (twoją "zabawką"). Dzięki temu możesz kontrolować interakcje z tym obiektem w bardzo szczegółowy sposób.
95
dispatchEvent
dispatchEvent triggering event
96
# Core WEB Vitals FCP
First Contentful Paint
97
# Core WEB Vitals LCP
Largest Contentful Paint
98
# Core WEB Vitals CLS
Cumultive Layout Shift
99
# Core WEB Vitals FID
First Input Delay