Programing Flashcards

typescirpt, javascript, webpack ,react

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
Q

Object.isExtensible():

A

Boolean check if an object is extensible.

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

Object.isSealed()

A

Boolean checking if an object is sealed.

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

Object.isFrozen()

A

Boolean checking if an object is frozen.

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

Thread of Execution

A

Story of the code execution, line by line

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

Function

A

Block of code that referance is saved in memory

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

Call Stack

A

Data structure working as LIFO where the active functions are stored and didn’t finish their work, its go one by one.

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

Higher Order Function

A

Functions that takes another function or returning a function

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

Arrow Functions

A

ES6 arrow function make a this asign to the context where was defined

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

Clousure

A

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

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

Task

A

SetTimeout, SetInterval, task are last to go

Thread of Execution > MicroTask > Task

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

MicroTask

A

Fetch, micro task are priorytaized before tasks but after Global Thread of Execution

Thread of Execution > MicroTask > Task

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

Promises

A

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

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

Class

A

ES6 Class simplify creating a Object

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

Object.create()

A

Object.create create a empty object but pass a “__proto__” as a hidden property

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

Increment/Preincrement

A
x=40
x++//40
x//41
\++x//42
41
Q

++

A

At fist take value make is a Number then add a 1

42
Q

Primitive Types

A

undefind, null, string, number, bigint, bolean, symbol,

43
Q

In JavaScript, everything is an object.

A

False, but most of things can beehive like a object

44
Q

In JavaScript, variables don’t have types, values do.

A
45
Q

typeof

A

Return a type of value stored in variable

46
Q

NaN is only value that is no equal to themselfs

A

NaN === NaN // false

47
Q

NaN: Invalid Number
NaN is always a Number

A
48
Q

Negative Zero

A

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
Q

Math.sign()

A

check the sign of number return 5 values

1, -1, 0, -0, NaN

50
Q

Fundamental Objects

Built-In Objects or Native Functions

A
51
Q

Use New:
1. Object()
2. Array()
3. Function()
4. Date()
5. RegExp()
6. Error()

A

Dont use new:
1. String()
2. Number()
3. Boolean()

52
Q

Coercion

A

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
Q

using double !!

A

! sign make a Coercion to bolean, double !! can make from !!0 = false

54
Q

Boolean()

A

Transform value to boolean

55
Q

Boxing

A

Boxing in JavaScript is the automatic conversion of primitive types to their corresponding object types to access methods and properties.

56
Q

Number(‘’),
Number(‘ \t\n’),
Number(null),
Number(undefined),
Number([]),
Number([1,2,3]),
Number([null]),
Number([undefined]),
Number({}),

A

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
Q

String(-0),
String(null),
String(undefined),
String([null]),
String([undefined]),
String(false),

A

String(-0), //”0”
String(null), // ‘null’
String(undefined), //’undefined’
String([null]), // ‘’
String([undefined]), // ‘’
String(false), // ‘’

58
Q

Boolean(new Boolean(false))

A

true

59
Q

Boolean

A

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
Q

1 < 2 < 3 = true but…

A

1 < 2 = true
true = 1
1 < 3

61
Q

3 > 2 > 1 = false

A

3 > 2 = true
tru = 1
1 > 1
False

62
Q

make a uniq array

A
    let newArray = [...new Set(array1.concat(array2))]; // Merge and remove duplicates
63
Q

== When the type match do the ===

A
64
Q

Dont use == with

A

== with 0 , ‘’, ‘ ‘
== with non-primitves
==true or == false allow ===

65
Q

use == only if u know a types

A
66
Q

console.log(undefined == null)//true

A
67
Q

Lexical Scope

A

Lexical Scopes tell us where we can find our functions and varibales

68
Q

JavaScript organizes scopes with functions and blocks

A
69
Q

Shadowing

A

Its happend if variable in inner scope have the same name as a variable in outer scope

70
Q

TypeError

A

When you try to do smth with incorect type

71
Q

auto global

A

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
Q

ReferenceError

A

“ReferenceError występuje, gdy próbujemy odwołać się do czegoś, co nie zostało zadeklarowane.”

73
Q

Function declaration vs Function Expresion

A

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
Q

Named Function Expressions

A

We giving our function expression a name

const getName = function getMyName() { console.log(‘Kamil’) }

75
Q

call()

A

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
Q

explicit binding

A

Explicit binding is a powerful feature in JavaScript that provides flexibility in how functions are called and applied.

77
Q

hard binding

A

Ensures that a function always executes with the specified this context, effectively “locking in” the function’s execution context ahead of time.

78
Q

new: steps

A
  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
Q

this in arrow function

A

this in arrow function works like in lexical scope

80
Q

Object is not a scope

A
81
Q

Super

A

Super is a reference to parent class

82
Q

Co to jest useState w React?

A

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
Q

What is the Link component in React Router and how is it used?

A

The Link component is used to navigate between pages in a React application. It generates an anchor (<a>) tag in the HTML document, allowing users to click on links to navigate to different routes without causing a page reload. This provides a smooth, seamless navigation experience within a single-page application (SPA). Syntax example: <link></link>About</Link></a>

84
Q

BrowserRouter

A

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
Q

Routes

A

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
Q

How does the Route component work in React Router?

A

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: <Route path=”/about” element={<About></About>} />

87
Q

UseState

A
88
Q

UseRef

A
89
Q

DOM

A

Document Model Object
connect the web pages to JavaScript by
representing the structrue of a document in memory

90
Q

DOM API

A

A browser API expose for developer to maintance the DOM from scripting language

91
Q

popstate

A

Event listener that listen for change url in same page navigation

92
Q

history.pushState

A

Allows for use to manipulate urls without reload the page

93
Q

substring

A
94
Q

new Proxy w JavaScript

A

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
Q

dispatchEvent

A

dispatchEvent triggering event

96
Q

Core WEB Vitals

FCP

A

First Contentful Paint

97
Q

Core WEB Vitals

LCP

A

Largest Contentful Paint

98
Q

Core WEB Vitals

CLS

A

Cumultive Layout Shift

99
Q

Core WEB Vitals

FID

A

First Input Delay