-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-query-questions
More file actions
2025 lines (1611 loc) · 110 KB
/
react-query-questions
File metadata and controls
2025 lines (1611 loc) · 110 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# JAVASCRIPT TYPESCRIPT
| Nm | #Question |
| :---: | :---: |
| 1 | [Difference let const var](#what-is-difference-between-let-const-var) |
| 2 | [Difference between arrow function and function declaration, expressions](#arrow-function-explanation) |
| 3 | [What is generator ](#generator-function) |
| 4 | [Types Enums Interface. What for are used types? What are tuples? What is union, intersection? What is intersection types? What is record type - provide example](#types-enums-interfaces) |
| 5 | [Difference between map, filter and forEach. Does filter, slice methods create new array or mutating source? What about reduce? ](#map-foreach-difference) |
| 6 | [What is this in js? Can you change value of this? What is this alone, inside object, inside event handler, inside function? What is for are used call,apply methods? If yout type this in console - what will you get?](#this-meaning) |
| 7 | [Is setTimeOut async?](#settimeout-async) |
| 8 | [What is Promise? Example of promise? What status promis returns? Is promise aycnronious? Name wayss of handling promises. What is promise all? Make a simple example of promise and promise.all](#example-promise) |
| 9 | [What is Closure? Please provide examples. If variable is declared without keyword, is it global?](#closure-explanation) |
| 10 | [What is differene between sppread and rest operator - name practical examples?](#rest-spread-operator-difference) |
| 11 | [What are sets? How to convert Set type to the array? Example.](#set-object) |
| 12 | [Why using try catch wrapper instead just async await?](#try-catch) |
| 13 | [types and interfaces diff? Can you shape type of object with types not interface?](#type-interface-diff) |
| 14 | [How to make array from collections js? What is js collection?](#collection-js-array) |
| 15 | [what is 3rd stringify parameter?](#stringify-3rd-parameter) |
| 16 | [what is difference between try block - catch/finally? Please provide an example](#try-catch-finally) |
| 17 | [what will be result of displaying this inside arrow function ?](#arrow-function) |
| 18 | [what is object assign ?](#object-assign) |
| 19 | [How does work object create? ?](#object-create) |
| 20 | [Name difference between copying primitive and object ( reference ) ? explain why let a = {};let b = {} not equal objects](#object-primitive-reference) |
| 21 | [Does nested function have an access to the outer function in JavaScript? And vice versa ( opposite) ](#inner-outer-function-scope) |
| 22 | [What is IIFE (immidietly invoked function expression](#immidietly-invoked-function-expression) |
| 23 | [What are module exports in js? What is module in js?](#module-exports) |
| 24 | [Why code .then(someFunction) works same as .then((data)=>someFunction(data)) ? What are functions in JS - and what can you do with function in JS?](#calling-function-reference) |
| 25 | [When you want to send json data to the server in what format should it be sent ?](#json-data-to-server) |
| 26 | [What is anonymous function in JS ?](#anonymous-function) |
| 27 | [What is nullish coalescing operator?](#nullish-coalescing) |
| 28 | [What is script diff, async difference?](#script-async-deffer) |
| 29 | [What is for used script tag?](#script-tag) |
| 30 | [Difference between inline and external js? What is an advantage of external js loading?](#inline-external-js) |
| 31 | [how can you test if a script has loaded successfully??](#loading-script-successfully) |
| 32 | [How can you prevent the browser from caching a JavaScript file?](#prevent-caching) |
| 33 | [What tools ( script loaders ) can you use for script loading?](#script-loaders) |
| 34 | [What are inferrede types in ts?](#inferred-types) |
| 35 | [What if you destructe some value and that value doesn't exist in object??](#destructing-object) |
| 36 | [If you filter 1 array through another array. Why it's bettr to use set ( it can be done with arrays filter method but... ) ?](#set-filtering-array) |
| 37 | [What are recursive types?](#recursive-types) |
| 38 | [For ... of, forEach difference?](#for-loops) |
| 39 | [Settimeout and asynchronous functions?](#settimeout-asynchronous-functions) |
| 40 | [ForEach, for...of difference??](#forEach-forOfDifference) |
# Exercises Javascript Typescript
| Nm | #Question |
| :---: | :---: |
| 1 | [What will be result of the next code?](#for-each-result-exercise) |
| 2 | [Split string by some string?](#split-string-exercise) |
| 3 | [Previoius state exampe?](#previous-state-example) |
| 4 | [Spread object with new key value?](#spread-object-kay-value) |
| 5 | [How to fix this infinite rendering problem in provided example?](#infinite-rendering) |
| 6 | [How recursion works in javascript?](#recursion-javascript) |
| 7 | [How to check if value is undefuined or null, if yes return other value ( some operator )?](#nullish-coalescing) |
| 8 | [How can be used useRef to fix rerender ( multipla calling code inside useEffect f.e.) of compnent?](#useRef-urerendering-explanation) |
| 9 | [Why do we use sometimes _ in js methods?](#underscore-js-methods-explanation) |
| 10 |[Which method do you need if you want to create empty array, map trhough it and fill it with some data?](#empty-array-mapping) |
let result = value ?? "default";
// If `value` is null or undefined, `result` will be "default"
# React
| Nm | #Question |
| :---: | :---: |
| 1 | [What is react](#what-is-react) |
| 2 | [What is unindirectional data flow](#what-is-unindirectional-data-flow) |
| 3 | [What is state in react?](#what-is-state-in-react) |
| 4 | [Can browser read JSX?](#can-browser-read-jsx) |
| 5 | [What is DOM, Virtual DOM?](#what-is-dom) |
| 6 | [What is difference between es5 and es6?](#difference-between-es5-es6) |
| 7 | [How to create basic React app?](#basic-react-app) |
| 8 | [what is event in React? What is synthetic event?](#what-is-event-in-react) |
| 9 | [Explain how lists work in React?](#lists-in-react) |
| 10 | [Why key should be added to the list elements? Why index shouldn't be added as index?](#keys-in-react-lists) |
| 11 | [What are the components in React?](#commponents-in-react) |
| 12 | [How to declare state in React?](#state-in-react) |
| 13 | [What are props in React?Are props mutable?](#props-in-react) |
| 14 | [What is state and props difference?](#state-props-difference) |
| 15 | [What is high ordered comopnent?](#high-ordered-component) |
| 16 | [UseEffect with lifeCycle methods. Useeffect and useState difference](#use-effect-lifecycle-methods) |
| 17 | [what is useMemo?](#use-memo) |
| 18 | [what are controlled and uncontrolled components?](#controlled-uncontrolled-componenent) |
| 19 | [what are react hooks? what is bad practices using hooks?](#react-hooks) |
| 20 | [what is useEffect and when we use it? what is difference in comparison to useLayouteffect? When useEffect is called?](#use-effect-hook) |
| 21 | [when do you need to use useCallback?](#use-callback) |
| 22 | [what is useRef hook? Example of use. Is value that useRef returns is mutable?](#use-ref) |
| 23 | [what is useRef useState difference?](#use-state-use-ref-diff) |
| 24 | [what is react context? when do we need it? Please list example of data stored in context](#react-context) |
| 25 | [what is the recommended way to structure your React code?](#react-structuring-code) |
| 26 | [what is good way to test your reactapplications?what is end-2-end testing? what is unit testing? What yuu use for unit testse](#react-test-how-work) |
| 27 | [what is react dev tools? When do you need it as rule?](#react-dev-tools) |
| 28 | [what is create portal? Provide some example of using it. What are downsides of useing portals?](#react-portals) |
| 29 | [what is lazy loading? Explain when you need it. What is difference between lazy loading and dynamic imports ](#lazy-loading-dynamic-imports) |
| 30 | [what is code splitting? What is lazy and suspense in react? Provide some example. What is Suspense built-int ](#code-splitting) |
| 31 | [what is SSR and CSR? Does Gatsby.js, NExt.js supports CSR or SSR? When pages are built in ssr in gatsby.js and when page are built in csr? What is advantage of using SSR? Provide some practical example of using SSR](#ssr-csr) |
| 32 | [what is fragment?](#fragment-explanation) |
| 33 | [what does mean useEffect with emtpy array?](#use-effect-empty-array) |
| 34 | [asd some example of hook?](#example-hook) |
| 35 | [Provide example of using event listener in react?](#event-listener) |
| 36 | [What is wrong with too many useEffect?](#too-many-useeffect-explain) |
| 37 | [JS design patterns used in React?](#design-patterns-react) |
| 38 | [How can you improve performance of react application with caching?](#caching-react) |
| 39 | [Is it good practice to assign state value directly to the input inside form?](#form-input-react-handling) |
| 40 | [Difference react hook and service](#react-hook-service-difference) |
| 41 | [virtual-dom-shadow-dom-difference](#virtual-dom-shadow-dom-difference) |
| 42 | [If we created element with react.createElement and want to render it in React 16. How to do it? Why it's deperecated and what is used now to render elment?](#react-create-element-react-dom) |
| 43 | [Why we don't use react proptypes in projects What is alternative??](#react-proptypes-question) |
| 44 | [What is event handler in React?](#react-event-handler) |
| 45 | [When to use forwardRef?](#forward-ref) |
| 46 | [When is pure function in react?](#pure-function) |
| 47 | [If i want to run something on component unmount. How to implement it in react??](#component-unmount) |
| 48 | [FC and simple () => function component declaration difference?](#fc-function-difference) |
| 49 | [How to use child state inside parent?](#parent-use-child-state) |
| 50 | [Rules of using custom hooks React?](#rules-custom-hooks-react) |
# Redux
| Nm | #Question |
| :---: | :---: |
| 1 | [What is redux?](#what-is-redux) |
| 2 | [What is redux action, store, reducer, dispatch?](#redux-action-store-reducer) |
| 3 | [Difference between redux, redux tools, react-redux library?](#redux-redux-tools-react-redux) |
| 4 | [Redux mobx difference?](#redux-mobx-difference) |
| 5 | [Why is it better to have few reducers sometimes??](#redux-reducers) |
| 6 | [Which library can be used to handle state immutability in redux, to improve work with redux state?](#redux-state-immutability) |
| 7 | [Is redux state immutable?](#redux-state-immutability-more) |
| 8 | [Immer library with redux state - why it's usefull?](#redux-immer-library) |
| 9 | [What is store subscribe?](#store-subscribe) |
| 10 | [What is middleware?](#what-is-middleware) |
| 11 | [What is redux thunk?](#what-is-redux-thunk) |
| 12 | [What is redux saga?](#what-is-redux-saga) |
| 13 | [Why do we use redux toolkit?](#redux-toolkit) |
| 14 | [Why do you need redux extra reducer?](#redux-extrareducer) |
| 15 | [What is for redux toolkit asynch thunks?](#redux-toolkit-async-thunk) |
| 16 | [What is for redux toolkit useSelector?](#redux-toolkit-use-selector) |
# React-native
| Nm | #Question |
| :---: | :---: |
| 1 | [What is react native](#what-is-react-native) |
| 2 | [How create class names, styles in react native?](#react-native-styling) |
# GATSBY.JS
| Nm | #Question |
| :---: | :---: |
| 1 | [What is gatsby.js?](#gatsby-framework) |
# REACT-QUERY
| Nm | #Question |
| :---: | :---: |
| 1 | [What is advantages of react-query? when do we use stale:infinity? so if i don't set staleTime what does it mean? will be my query cached? ](#react-query-questions) |
| 2 | [What is invalidating queries? Which cases of using do you know? ](#invalidating-queries) |
| 3 | [How does work refetchOnMount: false? ](#refetch-mount-false) |
| 4 | What is onSettled in react-query? ](#react-query-onsettled) |
# Other
| Nm | #Question |
| :---: | :---: |
| 1 | [Monorepo and polyrepo (microservices) difference, advantages, disadvantages](#monorepo-and-polyrepo-difference) |
| 2 | [What is webhooks? Name some real example. ](#what-is-webhooks) |
| 3 | [What is babel?](#what-is-babel) |
| 4 | [What is time complexity? Please provide examples](#time-complexity-space-complexity) |
| 5 | [Please name some frameworks](#name-some-front-end-frameworks) |
| 6 | [What is continues integration?](#continues-integration) |
| 7 | [Functional and OOP programming difference?](#functional-oop-programming) |
| 8 | [what is dependencies and devdependencies difference?](#dependencies-devdependencies-difference) |
| 9 | [what does it mean in package.json (scripts-typecheck)?](#package-json-scripts-typecheck) |
| 10 | [what does mean extensinos word in your paackage.json?](#extensions-word-package-json) |
| 11 | [Explain this line ("transpile:clean": "rimraf ./gatsby-*.js ./src/**/*.js") of packages.json scripots configuration?](#transiple-clean-explanation) |
| 12 | [What is markdown?](#markdown-explanation) |
| 13 | [What is web component? Key features. What is difference between iframe and web compnents](#web-components) |
| 14 | [what is lit library](#lit-library) |
| 15 | [what is lit library](#web-api) |
| 16 | [What is ways to improve performance of front-end application? What is prefetching? Code splitting?](#improving-performance) |
| 17 | [1. Ways to improve front-end security? 2. how can be done XSS (cross site scripting ) attack on your page? ](#front-end-security) |
| 18 | [How to improve WCAG standarts in your front-end app](#wcag-standarts)) |
| 19 | [Best practices for front-end](#best-practices-frontend)) |
| 20 | [SPA-PWA difference](#spa-pwa-difference)) |
| 21 | [Difference betwen SPA and gatsby.js, next.js pages](#spa-gatsby-next-difference) |
| 22 | [What is cookies? What is localstorage? What does have bigger size, bigger capacity? What do we store in localStorage nad what as rule do we store in cookies?](#localstorage-cookies) |
| 23 | [1. What is webpack? 2. Name difference between dev and prod webpack configuration. 3. Where is webpack configuration in gatsby.js, next.js frameworks? 4. "build": "webpack --mode production" - what will be result of this command?](#webpack-explanation) |
| 24 | [How to create ( generate ) packages.json file?](#creating-package-json)) |
| 25 | [Does react testing library work on rendered react components or on dom?](#react-testing-library)) |
| 26 | [What for are used render, screen methods imported from react testing library?](#render-screen-testing-react-library)) |
| 27 | [What is UTC time?](#utc-time-explanation)) |
| 28 | [If we want to run express server, that serves react-app - how to do it in short?](#express-server-react)) |
| 29 | [what is middleware function?](#middleware-function)) |
| 30 | [what is fs module in node.js?](#fs-module)) |
| 31 | [what is an advantage or react hook form?](#react-hook-form) |
| 32 | [what will do next axios header ''Content-Type': 'application/json'' in axios??](#axios-json-header) |
| 33 | [Difference ssr, ssg, isr?](#ssr-ssg-isr-difference) |
| 34 | [EXplain how SSG approach are used in more details?](#ssg-details) |
SPA:
Works by loading a single HTML page and dynamically updating the content as the user interacts with the app.
Uses AJAX calls to interact with the server, fetching and rendering data without reloading the entire page.
PWA:
Extends the functionality of traditional web apps with features like offline access, background sync, and push notifications, thanks to Service Workers.
Can be installed on a user's home screen like a native app and can run independently of the browser.
# CSS STYLING
| Nm | #Question |
| :---: | :---: |
| 1 | [What is box model ( what are parts of box model)? ](#box-model) |
| 2 | [What for wee need picture and sources ](#picture-sources) |
| 3 | [What is viewport? ](#viewport-what) |
| 4 | [What are possible values of position property? ](#position-property) |
| 5 | [What are types of selectors in css? ](#selectors-css) |
| 6 | [What is rem in css? ](#rem-css) |
| 7 | [What is benefit of styled components in comparison to normal css, style styling? ](#styled-components) |
| 8 | [Styled components and extending styles. how does it work (how can you create basic component and extended or just different version of component)? ](#styled-components-extending-styles) |
| 9 | [Difference betweein relative, absoulte, fixed, sticky? ](#relative-absolute-fixed-sticky) |
# HTML
| Nm | #Question |
| :---: | :---: |
| 1 | [What is HTML? Why we use it? ](#html-explanation) |
# GIT, DEPLOYMENT, PIPELINES
| Nm | #Question |
| :---: | :---: |
| 1 | [What is continuos deployment ( what is continues deployment)? ](#continuos-deployment) |
| 2 | [Git merge rebase difference? ](#merge-rebase-difference) |
| 3 | [What is cherry pick? ](#cherry-pick) |
# REDUX, REACT CONTEXT, REACT QUERY, STATE MANAGEMENT
| Nm | #Question |
| :---: | :---: |
| 1 | [Difference beteen react context and redux ](#react-context-redux) |
1. ### what is difference between let const var
**Var** - scope is global or function ( if var's used inside function ).
Let, const - they have block scope.
```javascript
if(true) {
let test = 'test'; // test variable is available only inside if block
}
```
**Let** - can be reasigned.
**Const** - can't be reasigned.
1. ### arrow function explanation
**Functional expression** - function defined inside an expression. Example:
```javascript
const getRectArea = function (width, height) {
return width * height;
};
console.log(getRectArea(3, 4));
```
**Functional declaration** - function declared with function keyword. Functional declaration creates binding of new function to a given name.
```javascript
function calcRectArea(width, height) {
return width * height;
}
console.log(calcRectArea(5, 6)););
```
```javascript
function print() {
console.log(arguments)
}
print(1,2,3,4);
/*
result below:
{
"0": 1,
"1": 2,
"2": 3,
"3": 4
}
*/
```
Remember arrow function don't have acces to the arguments.
```javascript
const obj = {
name: 'deeecode',
print: function() {
console.log(this)
}
}
obj.print() // {name: 'deeecode', print: ƒ}
```
You can't do smth like above with arrow function.
**Arrow function** - don't have binding to this ( in inherits this from outside look code example below), arguments, super and shouldn't be used as methods.
They can't be used as a constructors - we can't call them with new keyword. Cannot be used as generator functions.
Explain next examples:
```javascript
function Person() {
this.age = 0;
setInterval(() => {
this.age++; // `this` refers to the `Person` instance
console.log(this.age); // Correctly logs the incremented age
}, 1000);
}
let p = new Person();
```
```javascript
function Person() {
this.age = 0;
setInterval(function() {
this.age++; // `this` refers to the global object or `undefined` in strict mode
console.log(this.age); // NaN or throws error in strict mode
}, 1000);
}
let p = new Person();
```
So arrow functions do not have their own this. Instead, they inherit the value of this from the surrounding (lexical) context, which means the value of this is determined by where the arrow function is defined, not by how it is called.
1 more example:
normal function:
```javascript
const obj = {
name: "Alice",
greet: function() {
console.log(this.name); // `this` refers to `obj`
}
};
```
arrorw function:
```javascript
const obj = {
name: "Alice",
greet: () => {
console.log(this.name); // `this` does NOT refer to `obj`, but to the surrounding context (possibly `window` in non-strict mode or `undefined` in strict mode)
}
};
obj.greet(); // Output: undefined or global object, because `this` is inherited from the lexical scope
```
obj.greet(); // Output: Alice
3. ### Generator function
**Generator** is a process that can be paused and resumed and can yield multiple values. Generator returns iterable Geneartor object.
```javascript
function* generator(i) {
yield i;
yield i + 10;
yield i + 20;
}
const gen = generator(10);
console.log(gen.next().value);
// Expected output: 10
console.log(gen.next().value);
// Expected output: 20
console.log(gen.next().value);
// Expected output: 30
console.log(gen.next().value);
// Expected output: undefined
```
Calling .next() returns an object in form:
```javascript
{
value // current value of the iterator,
done // boolean indicating if iteration is finished
}
```
4. ### types enums interfaces
1. What are types, when do we use it?
**Types** are definitions of data type. Both're used to define type of data. Typescript compiler use it to detect errors.
2. What are **Tuples**?
```javascript
let ourTuple: [number, boolean, string];
``
Tuples are typed arrays
4. What are **Unions**?
A union type describes a value that can be one of several types.
```javascript
function printStatusCode(code: string | number) {
console.log(`My status code is ${code}.`)
}
```
5. An **intersection type** is a type that merges several kinds into one.
```javascript
interface Student {
student_id: number;
name: string;
}
interface Teacher {
Teacher_Id: number;
teacher_name: string;
}
type intersected_type = Student & Teacher;
let obj1: intersected_type = {
student_id: 3232,
name: "rita",
Teacher_Id: 7873,
teacher_name: "seema",
};
console.log(obj1.Teacher_Id);
console.log(obj1.name)
```
6. What are enums? When to use?
**Enums** are collection of constants
7. Types is used to type your values, to avoid errors and bugs.
Here more: https://blog.logrocket.com/typescript-enums-vs-types
8. Enums example:
```javascript
enum Names {
Vasyl,
Yaroslav,
Igor
}
var test = Names.Yaroslav;// 1
```
9. Interface: An interface is used to define a structure for an object.
10. Record is a utility type in TypeScript that constructs an object type with keys of type K and values of type T. An example:
Record<string, any> is a mapped type that creates an object type where the keys are strings, and the values can be of any type.
So, generally speaking, Record is type that helps to define an object with specific keys and values.
5. ### map-foreach-difference
**Map** return NEW array. It doesn't modify initial array.
**ForEach** doesn't return array. But runs function for each element of array. Foreach returns original array.
**Filter, slice** returns new array. They dont mutate initial array.
**Reduce** returns single accumulated value not an array.
7. ### this-meaning
1. This is keyword. It refers to different objects depending on how and where it used. The this keyword refers to the context where a piece of code, such as a function's body, is supposed to run.
2. You can explicitly control or change the value of this using methods like .call(), .apply(), or .bind(). For instance, using .bind() creates a new function with this permanently set to a specific value:
function greet() {
console.log(this.name);
}
const person = { name: 'Alice' };
const boundGreet = greet.bind(person);
boundGreet(); // logs "Alice".
3. ALone **this** refers to the global object. INside function - this refers to the global object also. In event handlers this refers to the hTML object.
```javascript
function dotest() {
console.log(this); // here we'll get Windows object
}
```
4. Call and apply methods are used to call 1 object method on another object as argument
6. If yout type this in console, you will get Window object.
8. ### settimeout-async
Yes setTimeout is async
9. ### example-promise
Promise object represents eventual completion or failure of asynchronous function. Whenever tasks should be executed asynchronouslo. Promisess are used.
Example login function:

Promise returns fullfilled or rejected status.
Promise is asyncchronous function.
Promises can be handled with:
**then catch**:
```javascript
const doPromise = () => {
new Promise((resolve, reject) => {
resolve({result: 5 });
}).then((data) => console.log(data))
.catch((error) => {
console.error('Promise rejected with error: ' + error);
});;
}
doPromise();
```
```javascript
Promise.then(() => datafetch).then(result => result).catch(()=>'error fetching data')
```
**asyn await try catch**
```javascript
async function main() {
try {
const doc = await db.doc("user/" + uid).get()
if (doc.exists) {
console.log("User data:", doc.data());
// use fetched data, for example in setState()
} else {
console.warn("No user data.");
}
}
catch(error) {
console.log("Error getting user data:", error);
}
}
```
Promise all (method) takes an array of promises and returns a single promise. The returned promise fullfills if all promises are executed, and noone fails.
```javascript
const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, 'foo');
});
Promise.all([promise1, promise2, promise3]).then((values) => {
console.log(values);
});
```
10. ### closure-explanation
1. If we speak about closure , we need to mention **local** and **global** scope. Functions have its local, private scope. Variables can be global or private - depending where they'are declared.
2. if variable is declared without keyword, it is global. Even if it's declared inside the function.
```javascript
function doTest() {
test = 5;
}
doTest();
console.log(test); // 5
```
Examples of global scope: window does have global scope. Variable declared with var outside of the fnction has global scop.e
11. ### rest-spread-operator-difference
1. ***Spread*** operator is mostly used with arrays. It's used to efficientl merge, cop arrays, pass elements to functions.
You can use spread operator to merge 2 objects,or 2 arrays. In React you can use spread operator to pass properties to the component:
```javascript
const props = {firstName: 'John', lastName: 'Doe'};
const component = <UserComponent {...props} />;
```
Example of copying array with spread operator:
```javascript
const arr = [1,2,3];
const copyArr = [...arr]
```
Example of merging 2 objects:
```javascript
const nameObject = { name: 'John' };
const surnameObject = { surname: 'Cool' };
const mergedObject = { ...nameObject, ...surnameObject };
```
Example passing arguments to functions:
```javascript
function sum(a, b, c) {
return a + b + c;
}
const nums = [1, 2, 3];
const result = sum(...nums);
console.log("Result of sum:", result); //6
**rest** operator can be used to extract the remaining properties. WHile spread operator used to exapand elements, rest operator used to condense elements into a single enti
```javascript
const {a, ...rest} = {a: 1, b: 2, c: 3};
console.log(rest); // {b: 2, c: 3}
```
It helps to get all arguments into an one array named numbers:
```javascript
function sum(...numbers) {
return numbers.reduce((total, num) => total + num, 0);
}
function printNumbers(...numbers) {
console.log(numbers); //
}
printNumbers(1,2,3,4,5); // [1,2,3,4,5]
```
12. ### set-object
Set are collections of unique values:
```javascript
const testArr = [1, 2, 1, 1];
const newSet = new Set(testArr);
console.log(testArr); // { 0:1, 1:2 }
```
if you want to convert it to the arr:
```javascript
console.log([...setValue]);
```
Set Object provides:
A **size** property that contains a number.
A **has()** method that takes an element and returns a boolean.
A **keys()** method that returns an iterator of the elements in the set.
13. ### try-catch
Wraps code that can fail and pass error to the catch instead of crashing the app.
So generally speaking we need it to handle errors.
14. ### type-interface-diff
Types in TypeScript are more flexible and can define primitive, intersection, union, tuple, or different types of data, while interfaces are used to describe the shape of an object
Yes you can use types to define typf of object.
```javascript
// With interface
interface Base {
id: number;
}
interface User extends Base {
name: string;
}
// With type
type Base = { id: number };
type User = Base & { name: string };
```
15. ### collection-js-array
Eather
```javascript
const arrray = [...yourObjectCollection];
// Or make it with Array.from
Array.from(yourObjectCollection)
```
In JavaScript, collections refer to data structures that store multiple elements or values. Examples include arrays, objects, maps, and sets
16. ### stringify-3rd-parameter
it adds additional spacing
17. ### try-catch-finally
Eather
```javascript
openMyFile();
try {
// tie up a resource
writeMyFile(theData);
} finally {
closeMyFile(); // always close the resource
}
```
or
```javascript
try {
// try_statements
} catch(error) {
// catch_statements
}
finally() {
// codes that gets executed anyway
}
```
18. ### arrow-function
This inside arrow function is referenced, pointed to the global object. We normal function declaration - it points to the inner scope.
```javascript
function RegularFunction() {
this.value = 10;
setTimeout(function () {
console.log(this.value); // undefined, because `this` refers to the global object or is undefined in strict mode. It should be remembered that for example in chrome, it can console 10 instead of undefined ( it's connected with specific chrome console aspects ).
}, 100);
}
function ArrowFunction() {
this.value = 20;
setTimeout(() => {
console.log(this.value); // 20, because `this` is inherited from ArrowFunction's scope
}, 100);
}
new RegularFunction(); // Logs: undefined
new ArrowFunction(); // Logs: 20
```
18. ### object-assign
Object assign method is used to clone or copy proeperties from 1 object to another.
```javascript
const obj = { a: 1 };
const copy = Object.assign({}, obj);
console.log(copy); // { a: 1 }
You can add 1 target object, and 2 source objects like that:
Object.assign({}, product, {
votes: product.votes + 1,
});
```
19. ### object-create
With help of Object.create we can create an new object from a given prototype object. It retrns a new object with the prototype set to given object.
```javascript
const myPrototype = {
size: 'large',
getSize() {
return this.size;
}
};
const myObject = Object.create(myPrototype);
console.log(myObject.getSize()); // 'large'
```
It can also be used Object.create to create subobject, which inherits properties and methods from their parent objects.
```javascript
const mySubObject = Object.create(myObject, {
color: { value: 'red' }
});
```
console.log(mySubObject.getSize()); // 'large'
console.log(mySubObject.color); // 'red'
20. ### object-primitive-reference
Object is stored and copied "by reference", whereas primitive values strings, numbers, booleans copied as a whole value.
```javascript
let message = "Hello!";
let phrase = message;
```
In the end we have 2 independent variables.
A variable assigned to an object = stores not object itslef, but its address in memory, in other words - a reference to it.
```javascript
let user = { name: "John" };
let admin = user;
```

When objects are equal?

Two independent objects are not equal:
let a = {};
let b = {}; // two independent objects
alert( a == b ); // false
21. ### inner-outer-function-scope
Outer function doesn't have an access to the inner functions. But inner functions have an access to the outer functions. It's how lexical scope does work.
22. ### immidietly-invoked-function-expression
Function runs as soon as it's defined.
```javascript
(function () {
// …
})();
(() => {
// …
})();
```
When to Use IIFEs:
Creating private scope for variables.
Avoiding global namespace pollution in scripts.
Simulating modules or public/private APIs in legacy code.
Executing setup or initialization code immediately.
23. ### module-exports
Module exports - is a way to expose functions, objects and primitives from module, so they can be used later in your code.
An example:

And if we need to import it, we do it that way:

Module has different properties, one of them is exports, if you will do console.log(module).
Remember also yuo have 2 other options ( its expecially often is used in React.jss) export default and export.

A module is a chunk of code in an external file that performs a specific task or function. It is a separate entity within a program, allowing for modularity and code reusability.
By encapsulating related code into modules, developers can organize their programs more efficiently and make them easier to maintain
24. ### calling-function-reference
IN js when we pass a function by reference it is automatically called with the argument that the previous 'then' resolves to.
JavaScript functions are first-class objects, meaning:
Functions can be assigned to variables or properties.
Functions can be passed as arguments to other functions.
Functions can be returned from other functions.
What is ***"Reference"***? A reference is essentially a pointer to the actual location of the function in memory. When you pass a function to another variable or as an argument, you're providing access to the same function, not creating a copy.
25. ### json-data-to-server
Yes, before sending json to the server. You should convert it to the string.
26. ### anonymous-function
Anonymous function - is function declared without function name.There is 2 different ways of using it.

27. ### #nullish-coalescing
The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.

28. ### #script-async-deffer

***Defer*** attribute is useful when script is using for DOM manipulations. Means script will apply on document html.
***Async*** attribute is useful when script is not using for DOM manipulation. Some time you need script only for server side operations or for handling cache or cookie but not for DOM manipulations
29. ### #script-tag
Script tag is used to load some javascript code into your page.
30. ### #inline-external-js
Inline javascript is used directly in your html. External JS is contained as a sepearate file.
External scripts is preferred - cause it can be cached by the browser and reused across multiple pages.
31. ### #loading-script-successfully
We can test if a scripthas loadded successfully by checking if a global variable or function defined in the script ia available.
32. ### #prevent-caching
WE can prevent the browser from caching a js file by providing some unique query string to the URL of the file.
An example:
```javascript
<script src="hellojs.js?v=1"></script>
```
33. ### #script-loaders
It can be used Require.js or webPack for example.It provides advanced functionality for loading and managing Javascript files such as lazyLoading, dependency management, error handling.
34. ### #inferred-types


35. ### #inferred-types

result will be undefined.
36. ### #set-filtering-array
```javascript
const arr1 = ['apple', 'banana', 'orange', 'red'];
const arr2 = ['green', 'yeelo', 'red', 'blue', 'orange'];
const arrWithSet = new Set(arr1);
const resultWithSet = arr2.filter(elem => arrWithSet.has(elem));
```
Set is better cause it's faster. Includes array method will loop through each element. But set will directly find it via hash key.
Set.has() O(1) Instead of O(n)
37. ### #recursive-types
example of recursive types:
```javascript
export type TreeNode = {
key: string;
title: React.ReactNode;
children?: TreeNode[];
};
```
37. ### #for-loops
forEach does not support returning values
Unlike a regular for loop, forEach does not return values or allow return to stop execution.
39. ### #settimeout-asynchronous-functions
Functions running in parallel with other functions are called ***asynchronous***.
SetTimeout is asynchronous, but it does not return a Promise like async functions do. Instead, it uses callback-based execution.
JavaScript runs synchronously by default, but async operations (e.g., setTimeout, fetch, Promise) use the event loop.
The function inside ****setTimeout**** is executed by the event loop after the specified delay.
Common problem interview with settimeout inside loops:

var is function-scoped, so all setTimeout callbacks share the same i reference.
Common question:

How to use setTimeout inside async function?

40. ### #forEach-forOfDifference
***for...of*** supports break, continue.
***forEach*** - Can access index as a second argument
forEach is used for simpler problems.
__________________________________________________________________________________________________________________________________________
# Exercises Javascript Typescript
1. ### for-each-result-exercise
```javascript
const names = ["Rohit","Aakash","Vinay","Ashish","Vasu"];
const tes = names.forEach((item) => item + 'lolo');
```
Answer: it will be undefined, cause forEach doesn't return any walue, it just runs function for each element of array
2. ### split-string-exercise
```javascript
var s = 'john smith~123 Street~Apt 4~New York~NY~12345';
s.split('~')
```
3. ### previous-state-example
Count example (to get previous state we need to put callback function):

4. ### spread-object-kay-value
```javascript
const test = { test: 'test '};
{...test, name: 'pame'}
```
5. ### infinite-rendering

Answer -setCounter should be used out of useEffect here to prevent infinite rendering problem.
6. ### recursion-javascript


7. ### nullish coalescing
let result = value ?? "default";
// If `value` is null or undefined, `result` will be "default"
// Otherwise, `result` will be the value of `value`
8. ### useRef rerendering explanation
const isInitialRender = useRef(true);
useEffect(() => {
if (isInitialRender.current) {
isInitialRender.current = false;
fetchData(pagination.current, pagination.pageSize);
}
}, []);
Explanation: Component renders for the first time. UseRef created reference object.
useEffect runs:
isInitialRender.current is true, fetches data.
Sets isInitialRender.current to false.
On subsequent renders, useEffect does not run again (due to the empty dependency array), and fetchData is not called.
9. ### underscore js methods explanation
```javascript
(_, index) => ({
title: `Col ${index + 1}`,
dataIndex: `col${index + 1}`,
key: `col${index + 1}`,
})
```
_ (underscore): Represents the current value (not needed since we're just using the index). So if you see it, in most cases it's just suggests that this value will not be used.
10. ### empty-array-mapping
```javascript
const columns = Array.from({ length: 11 }, (_, index) => ({
title: `Col ${index + 1}`,
dataIndex: `col${index + 1}`,
key: `col${index + 1}`,
}));
```
First part creates array with empty values.
2nd part iterates through empty slots and fills it with data.
__________________________________________________________________________________________________________________________________________
1. ### What is react
**React** - is library. Main React features:
1. JSX - js extension. We can write HTML structures inside JS. For example use HTML structures inside if structure:

2. Components - we create reusable, independent components.
3. Virtual DOM - it's virtual copy of DOM, with help of it preformance is improved. With help of that we update only necessary things in DOM, not rebuilding all DOM tree.
4. One way data-binding.
5. high performance - while updating components - we don't refresh, update all application.
______________
2. ### What is unindirectional data flow
Children component're placed inside parent component. Data's transfered from parent component to child component. Benefits unindirectional data-flow:
1. Easy to debug - cause we know how and frome where data is coming.
2. Less errors - more control on data.
______________
3. ### What is state in react
State in React - is object containing component an information. It can be changed. When state's changed, component is rerendered.
Remember not to mutate directly React's state, cause it can lead to different problems, bugs.
When state's updated, react calls render() method and component's updated.
Generally speaking, any time a component needs to hold a dnynamic piece of data - you need a state to use it.
______________