-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquestion.json
4642 lines (4642 loc) · 414 KB
/
question.json
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
[
{
"title": "What is IndexedDB",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448276165661314336",
"level": "basic",
"theme": "IndexedDB, db, storage",
"text": "### What is IndexedDB?\n\nIndexedDB is a low-level API for storing large amounts of structured data, including files and blobs. It allows developers to perform advanced queries and store data persistently in a user's browser. This API is particularly useful for web applications that need to work offline or require local storage beyond simple key-value pairs.",
"link": "#what-is-indexeddb"
},
{
"title": "What are the options in a cookie",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448261980567145761",
"level": "basic",
"theme": "cookie, options, storage",
"text": "### What are the options in a cookie?\n\nCookies have several options to control their behavior, such as `path`, `domain`, `secure`, `HttpOnly`, and `SameSite`. These options help define the scope, security, and accessibility of the cookie.",
"link": "#what-are-the-options-in-a-cookie"
},
{
"title": "Differences between cookie, local storage and session storage",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448258461030173985",
"level": "basic",
"theme": "cookie, local storage, session storage, differences",
"text": "### Differences between cookie, local storage, and session storage\n\nCookies are primarily used for server communication and have size limitations. Local storage provides persistent client-side storage with no expiration, while session storage stores data for the duration of a session.",
"link": "#differences-between-cookie-local-storage-and-session-storage"
},
{
"title": "How do you delete a cookie",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448236859966197025",
"level": "intermediate",
"theme": "cookie, delete, remove",
"text": "### How do you delete a cookie?\n\nTo delete a cookie, set its expiration date to a past date using the `Set-Cookie` header or JavaScript's `document.cookie`. Ensure you match the path and domain attributes of the cookie.",
"link": "#how-do-you-delete-a-cookie"
},
{
"title": "What is a post message",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448205399074934049",
"level": "intermediate",
"theme": "postMessage, communication, iframe",
"text": "### What is a post message?\n\nThe `postMessage` API allows secure communication between a parent window and iframes or between different windows. It is commonly used for cross-origin communication in web applications.",
"link": "#what-is-a-post-message"
},
{
"title": "What are closures",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447942704148811041",
"level": "intermediate",
"theme": "closures, JavaScript, scope",
"text": "### What are closures?\n\nClosures in JavaScript occur when a function retains access to its lexical scope even after the function in which it was defined has completed execution. They enable powerful programming patterns like encapsulation and callbacks.",
"link": "#what-are-closures"
},
{
"title": "What are modules",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447936859029654816",
"level": "intermediate",
"theme": "modules, JavaScript, ES6",
"text": "### What are modules?\n\nModules are reusable blocks of code that can be imported and exported in JavaScript. They help organize and encapsulate functionality, promoting maintainable and modular codebases.",
"link": "#what-are-modules"
},
{
"title": "What are classes in ES6",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447909741977685280",
"level": "advanced",
"theme": "classes, ES6, object-oriented programming",
"text": "### What are classes in ES6?\n\nClasses in ES6 provide a syntax for object-oriented programming in JavaScript. They include constructors, methods, and inheritance, making it easier to create and manage objects.",
"link": "#what-are-classes-in-es6"
},
{
"title": "Why do you need modules",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447895686626020640",
"level": "intermediate",
"theme": "modules, benefits, organization",
"text": "### Why do you need modules?\n\nModules help organize code into manageable pieces, improve reusability, and avoid global namespace pollution. They also make dependency management and code maintenance easier.",
"link": "#why-do-you-need-modules"
},
{
"title": "What is Hoisting",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447882385946938656",
"level": "basic",
"theme": "hoisting, JavaScript, scope",
"text": "### What is Hoisting?\n\nHoisting in JavaScript refers to the process where variable and function declarations are moved to the top of their scope during compilation. This allows variables to be used before they are declared.",
"link": "#what-is-hoisting"
},
{
"title": "What is scope in javascript",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447877473280265505",
"level": "basic",
"theme": "scope, JavaScript, variables",
"text": "### What is scope in JavaScript?\\n\\nScope determines the accessibility of variables and functions in JavaScript. There are two types of scope: global and local. Modern JavaScript also includes block scope with \\`let\\` and \\`const\\`.",
"link": "#what-is-scope-in-javascript"
},
{
"title": "What is a service worker",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447871707219594529",
"level": "advanced",
"theme": "service worker, offline, caching",
"text": "### What is a service worker?\n\nA service worker is a script that runs in the background, separate from the web page, enabling features like offline functionality, push notifications, and background sync. It acts as a proxy between the web app and the network.",
"link": "#what-is-a-service-worker"
},
{
"title": "How do you manipulate with DOM element",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447865971974475041",
"level": "basic",
"theme": "DOM manipulation, JavaScript, elements",
"text": "### How do you manipulate a DOM element?\n\nTo manipulate DOM elements, use methods like `document.getElementById`, `document.querySelector`, and properties like `.innerHTML`, `.style`, or methods like `appendChild` and `removeChild` to modify elements dynamically.",
"link": "#how-do-you-manipulate-with-dom-element"
},
{
"title": "How do you reuse information across service worker restarts",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447841580880350497",
"level": "advanced",
"theme": "service worker, persistence, IndexedDB",
"text": "### How do you reuse information across service worker restarts?\n\nTo reuse information across service worker restarts, store data in persistent storage mechanisms like IndexedDB or localStorage. This ensures data remains accessible even when the service worker restarts.",
"link": "#how-do-you-reuse-information-across-service-worker-restarts"
},
{
"title": "What is IndexedDB",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447814335323278624",
"level": "advanced",
"theme": "IndexedDB, database, storage",
"text": "### What is IndexedDB?\n\nIndexedDB is a low-level API for storing large amounts of structured data, including files and blobs. It allows advanced querying and persistent storage, making it ideal for offline-capable applications.",
"link": "#what-is-indexeddb"
},
{
"title": "What is memoization",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447658154155871520",
"level": "intermediate",
"theme": "memoization, caching, performance",
"text": "### What is memoization?\n\nMemoization is an optimization technique where function results are cached based on input arguments, avoiding redundant computations and improving performance.",
"link": "#what-is-memoization"
},
{
"title": "What is memoization",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447658154155871520",
"level": "intermediate",
"theme": "memoization, caching, performance",
"text": "### What is memoization?\n\nMemoization is an optimization technique where function results are cached based on input arguments, avoiding redundant computations and improving performance.",
"link": "#what-is-memoization"
},
{
"title": "What is a Prototype Chain in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447534074211601697",
"level": "basic",
"theme": "prototype, inheritance, JavaScript",
"text": "### What is a Prototype Chain in JavaScript?\n\nThe prototype chain is a fundamental concept in JavaScript's inheritance model. Every object in JavaScript has a prototype, which is another object. When you access a property of an object, JavaScript will first look for it in the object itself. If not found, it will look in the object's prototype, and then the prototype's prototype, and so on, until it reaches `null`.",
"link": "#what-is-a-prototype-chain-in-javascript"
},
{
"title": "What is a higher order function",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447469800642727200",
"level": "intermediate",
"theme": "higher order functions, JavaScript",
"text": "### What is a higher order function?\n\nA higher order function is a function that either takes one or more functions as arguments, returns a function, or both. This allows for more abstract and reusable code. Examples of higher order functions include `map()`, `filter()`, and `reduce()` in JavaScript.",
"link": "#what-is-a-higher-order-function"
},
{
"title": "What is the currying function",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447172210076208417",
"level": "advanced",
"theme": "currying, functions, JavaScript",
"text": "### What is the currying function?\n\nCurrying is a technique in functional programming where a function that takes multiple arguments is transformed into a sequence of functions, each taking a single argument. This can make the code more modular and reusable. For example, `function add(a) { return function(b) { return a + b; } }`.",
"link": "#what-is-the-currying-function"
},
{
"title": "How do you compare Object and Map",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447122335863147808",
"level": "advanced",
"theme": "Object, Map, JavaScript",
"text": "### How do you compare Object and Map?\n\nBoth `Object` and `Map` are key-value stores in JavaScript, but they have differences:\n\n1. **Key Types**: `Map` can use any data type as a key, while `Object` keys are always converted to strings.\n2. **Iteration**: `Map` preserves the order of insertion, while `Object` does not guarantee order.\n3. **Performance**: `Map` is generally more efficient for frequent additions and removals of key-value pairs.",
"link": "#how-do-you-compare-object-and-map"
},
{
"title": "What is a pure function",
"url": "https://www.tiktok.com/@jsmentoring/photo/7447104096424725792",
"level": "advanced",
"theme": "pure function, functional programming",
"text": "### What is a pure function?\n\nA pure function is a function that, given the same input, will always return the same output and does not have any side effects. It does not modify any external state or depend on external variables. This makes pure functions predictable and easier to test, as well as a key concept in functional programming.",
"link": "#what-is-a-pure-function"
},
{
"title": "What is a Prototype Chain in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446735468848270625",
"level": "basic",
"theme": "prototype, inheritance, JavaScript",
"text": "### What is a Prototype Chain in JavaScript?\n\nThe prototype chain is a fundamental concept in JavaScript's inheritance model. Every object in JavaScript has a prototype, which is another object. When you access a property of an object, JavaScript will first look for it in the object itself. If not found, it will look in the object's prototype, and then the prototype's prototype, and so on, until it reaches `null`.",
"link": "#what-is-a-prototype-chain-in-javascript"
},
{
"title": "What is the purpose of the let keyword",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446499450626772256",
"level": "basic",
"theme": "let keyword, JavaScript",
"text": "### What is the purpose of the let keyword?\n\nThe `let` keyword in JavaScript is used to declare block-scoped variables. Unlike `var`, which declares variables globally or within a function scope, `let` restricts the variable's scope to the block, statement, or expression in which it is used. This makes `let` more predictable and avoids issues with variable hoisting.",
"link": "#what-is-the-purpose-of-the-let-keyword"
},
{
"title": "Arrow func?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446420047448247585",
"level": "basic",
"theme": "arrow functions, JavaScript",
"text": "### Arrow func?\n\nArrow functions in JavaScript are a shorter syntax for writing functions. They are defined using `=>` and do not have their own `this` value, which means they inherit `this` from the surrounding context. This makes them useful in situations like event handling and callbacks where `this` behavior can be tricky.",
"link": "#arrow-func"
},
{
"title": "What is the difference between let and var",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446417854699687200",
"level": "basic",
"theme": "let, var, JavaScript",
"text": "### What is the difference between let and var?\n\nThe primary differences between `let` and `var` are their scoping rules and hoisting behavior:\n\n1. **Scope**: `let` is block-scoped, while `var` is function-scoped.\n2. **Hoisting**: Both `let` and `var` are hoisted to the top of their scope, but `let` is not initialized until the code execution reaches it, leading to a Temporal Dead Zone (TDZ).",
"link": "#what-is-the-difference-between-let-and-var"
},
{
"title": "What is git bisect command?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446337497484791073",
"level": "advanced",
"theme": "git, bisect, debugging",
"text": "### What is git bisect command?\n\nThe `git bisect` command is used to find the commit that introduced a bug by performing a binary search. You start by marking a known good commit and a known bad commit. Git then checks out the midpoint commit, and you test it. Based on the result, Git narrows down the range of commits until the problematic one is found.",
"link": "#what-is-git-bisect-command"
},
{
"title": "What are lambda expressions or arrow functions?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446080608989678880",
"level": "basic",
"theme": "lambda expressions, arrow functions, JavaScript",
"text": "### What are lambda expressions or arrow functions?\n\nLambda expressions, also known as arrow functions, are a concise way to write functions in JavaScript. They use the `=>` syntax and do not have their own `this` value, meaning they inherit `this` from the surrounding context. They are often used for short, anonymous functions in callbacks or array methods.",
"link": "#what-are-lambda-expressions-or-arrow-functions"
},
{
"title": "What is the difference between == and === operators?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446055928723508512",
"level": "basic",
"theme": "JavaScript",
"text": "### What is the difference between == and === operators?\n\nIn JavaScript, `==` is the equality operator that compares values after performing type coercion, meaning it converts the values to a common type before comparing them. On the other hand, `===` is the strict equality operator, which compares both the value and the type without any type conversion.",
"link": "#what-is-the-difference-between-and-operators"
},
{
"title": "What is the purpose of the array splice method?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446035575565520160",
"level": "basic",
"theme": "splice, array, JavaScript",
"text": "### What is the purpose of the array splice method?\n\nThe `splice()` method in JavaScript is used to modify an array by adding, removing, or replacing elements. It takes at least two arguments: the index at which to start changing the array, and the number of elements to remove. Additional arguments can be provided to add new elements.",
"link": "#what-is-the-purpose-of-the-array-splice-method"
},
{
"title": "What is the difference between slice and splice?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7446029933446565152",
"level": "basic",
"theme": "slice, splice, JavaScript",
"text": "### What is the difference between slice and splice?\n\n`slice()` is used to extract a shallow copy of a portion of an array without modifying the original array, while `splice()` is used to change the contents of an array by removing or replacing elements. The key difference is that `slice()` does not alter the array, while `splice()` does.",
"link": "#what-is-the-difference-between-slice-and-splice"
},
{
"title": "5 Ways to Create Objects in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7445448146685136161",
"level": "basic",
"theme": "objects, creation, JavaScript",
"text": "### 5 Ways to Create Objects in JavaScript\n\nIn JavaScript, objects can be created in various ways. The five most common methods are:\n\n1. **Object Literal**: `const obj = {}`\n2. **Object Constructor**: `const obj = new Object()`\n3. **Object.create()**: `const obj = Object.create(null)`\n4. **Class Syntax**: `class MyClass { constructor() {} }`\n5. **Factory Functions**: `function createObject() { return {}}`",
"link": "#5-ways-to-create-objects-in-javascript"
},
{
"title": "What is git rebase command?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7444874869394771232",
"level": "basic",
"theme": "git, rebase, version control",
"text": "### What is git rebase command?\n\nThe `git rebase` command is used to integrate changes from one branch into another. It works by moving or 'replaying' commits from one branch onto another, creating a linear history. This is different from `git merge`, which creates a merge commit. `git rebase` can be used to keep a cleaner, more linear commit history.",
"link": "#what-is-git-rebase-command"
},
{
"title": "What is git reflog command?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7444873101717884192",
"level": "basic",
"theme": "git, reflog, version control",
"text": "### What is git reflog command?\n\nThe `git reflog` command is used to show the history of changes to the reference logs, which track updates to the branches in a repository. This can be useful for recovering lost commits or understanding the changes made to a branch, especially after actions like rebasing or resetting.",
"link": "#what-is-git-reflog-command"
},
{
"title": "What is git revert command?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7444867368431439136",
"level": "basic",
"theme": "git, revert, version control",
"text": "### What is git revert command?\n\nThe `git revert` command is used to create a new commit that undoes the changes made by a previous commit. Unlike `git reset`, which alters the commit history, `git revert` preserves the commit history and is often used in shared repositories to undo changes safely.",
"link": "#what-is-git-revert-command"
},
{
"title": "What is a storage event and its event handler?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448353911720742177",
"level": "intermediate",
"theme": "storage event, event handler, web storage",
"text": "### What is a storage event and its event handler?\n\nA storage event is triggered when a change is made to the `localStorage` or `sessionStorage` in the browser, such as adding, removing, or modifying a key-value pair. The event handler for this event allows you to respond to these changes, providing a way to synchronize or react to storage updates across different windows or tabs.",
"link": "#what-is-a-storage-event-and-its-event-handler"
},
{
"title": "What are the methods available on session storage?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448368128825888032",
"level": "basic",
"theme": "sessionStorage, web storage",
"text": "### What are the methods available on session storage?\n\n`sessionStorage` provides methods to interact with the browser's session storage. Key methods include:\n\n- `setItem(key, value)`: Adds a key-value pair.\n- `getItem(key)`: Retrieves the value for a given key.\n- `removeItem(key)`: Removes the key-value pair.\n- `clear()`: Clears all data stored in sessionStorage.",
"link": "#what-are-the-methods-available-on-session-storage"
},
{
"title": "How do you access web storage?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448375078183587105",
"level": "basic",
"theme": "web storage, sessionStorage, localStorage",
"text": "### How do you access web storage?\n\nWeb storage is accessed using the `localStorage` or `sessionStorage` objects in JavaScript. For example, you can use `localStorage.setItem('key', 'value')` to store data, and `localStorage.getItem('key')` to retrieve it. Both `localStorage` and `sessionStorage` are part of the Window interface and provide a simple API for storing key-value pairs.",
"link": "#how-do-you-access-web-storage"
},
{
"title": "What is the main difference between localStorage and sessionStorage?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448379916778851617",
"level": "basic",
"theme": "localStorage, sessionStorage, web storage",
"text": "### What is the main difference between localStorage and sessionStorage?\n\nThe main difference is the lifespan of the stored data:\n- **`localStorage`** persists data even after the browser is closed, and the data remains available until explicitly removed.\n- **`sessionStorage`** only stores data for the duration of the page session. Once the tab or window is closed, the data is cleared.",
"link": "#what-is-the-main-difference-between-localstorage-and-sessionstorage"
},
{
"title": "Why do you need a Cookie?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448385477113171233",
"level": "intermediate",
"theme": "cookies, web storage, HTTP",
"text": "### Why do you need a Cookie?\n\nCookies are used to store data on the client-side, typically for purposes like tracking user sessions, saving preferences, or authenticating users. They are sent to the server with every HTTP request, allowing the server to remember information about the client across requests and sessions.",
"link": "#why-do-you-need-a-cookie"
},
{
"title": "What is a Cookie?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448395347279236384",
"level": "basic",
"theme": "cookies, web storage, HTTP",
"text": "### What is a Cookie?\n\nA cookie is a small piece of data stored by the browser on the client-side. It is sent to the server with every HTTP request and is used for various purposes such as maintaining user sessions, tracking user activity, and storing preferences.",
"link": "#what-is-a-cookie"
},
{
"title": "What is web storage?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448401312728878368",
"level": "basic",
"theme": "web storage, localStorage, sessionStorage",
"text": "### What is web storage?\n\nWeb storage provides a way to store data in the browser. It includes two types: `localStorage` and `sessionStorage`. `localStorage` stores data persistently, while `sessionStorage` stores data for the duration of a session, which is cleared when the browser or tab is closed.",
"link": "#what-is-web-storage"
},
{
"title": "What Are Server-Sent Events (SSE)?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448434434774142240",
"level": "intermediate",
"theme": "SSE, real-time communication, web technologies",
"text": "### What Are Server-Sent Events (SSE)?\n\nServer-Sent Events (SSE) is a technology that allows a server to push updates to the client over a single HTTP connection. This is typically used for real-time applications such as notifications, live scores, or chat apps, where the server sends updates to the client automatically.",
"link": "#what-are-server-sent-events-sse"
},
{
"title": "What Is a Callback Hell?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448549870673169696",
"level": "intermediate",
"theme": "callback hell, asynchronous, JavaScript",
"text": "### What Is a Callback Hell?\n\nCallback hell, also known as 'Pyramid of Doom,' refers to a situation where multiple nested callback functions in JavaScript make the code hard to read and maintain. It usually occurs in asynchronous code and can be mitigated by using Promises or async/await.",
"link": "#what-is-a-callback-hell"
},
{
"title": "Importance of Callbacks in Javascript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448582345390591265",
"level": "basic",
"theme": "callbacks, JavaScript, asynchronous programming",
"text": "### Importance of Callbacks in Javascript?\n\nCallbacks in JavaScript are functions passed as arguments to other functions, enabling asynchronous programming. They allow for non-blocking code execution, making it possible to handle events like user input or network requests without freezing the application.",
"link": "#importance-of-callbacks-in-javascript"
},
{
"title": "What is a callback function in javascript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448614606278282529",
"level": "basic",
"theme": "callback function, JavaScript, asynchronous programming",
"text": "### What is a callback function in javascript?\n\nA callback function is a function passed into another function as an argument and executed after the completion of a task. Callbacks are commonly used in asynchronous programming, such as handling events or making HTTP requests.",
"link": "#what-is-a-callback-function-in-javascript"
},
{
"title": "What Are the Three States of a Promise?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448655823150058785",
"level": "intermediate",
"theme": "Promise, JavaScript, asynchronous programming",
"text": "### What Are the Three States of a Promise?\n\nA Promise in JavaScript can be in one of three states:\n- **Pending**: The initial state, neither fulfilled nor rejected.\n- **Fulfilled**: The operation completed successfully.\n- **Rejected**: The operation failed.",
"link": "#what-are-the-three-states-of-a-promise"
},
{
"title": "Why do you need a promise?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448671709634235681",
"level": "intermediate",
"theme": "Promise, asynchronous programming",
"text": "### Why do you need a promise?\n\nPromises are used to handle asynchronous operations in JavaScript. They provide a cleaner way to handle asynchronous code, avoiding callback hell by chaining `.then()` and `.catch()` methods to handle success and failure, respectively.",
"link": "#why-do-you-need-a-promise"
},
{
"title": "What is a promise?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448715825642540320",
"level": "intermediate",
"theme": "Promise, JavaScript, asynchronous programming",
"text": "### What is a promise?\n\nA promise is an object in JavaScript that represents the eventual completion (or failure) of an asynchronous operation and its resulting value. It allows you to attach `.then()` and `.catch()` methods to handle the results or errors of the asynchronous task.",
"link": "#what-is-a-promise"
},
{
"title": "What are the restrictions of web workers on DOM?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448725365574372641",
"level": "advanced",
"theme": "web workers, DOM, JavaScript",
"text": "### What are the restrictions of web workers on DOM?\n\nWeb workers run in a separate thread and cannot directly access or modify the DOM. They are designed for heavy computations and background tasks. To interact with the DOM, workers communicate with the main thread using message passing via `postMessage()`.",
"link": "#what-are-the-restrictions-of-web-workers-on-dom"
},
{
"title": "Give an example of a web worker?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448739040213437729",
"level": "intermediate",
"theme": "web workers, JavaScript",
"text": "### Give an example of a web worker?\n\nA simple web worker example:\n\n```javascript\nconst worker = new Worker('worker.js');\nworker.postMessage('Hello');\nworker.onmessage = function(event) {\n console.log('Received from worker:', event.data);\n};\n```\nIn the `worker.js` file, you would handle the message with `onmessage` and use `postMessage` to send a response back.",
"link": "#give-an-example-of-a-web-worker"
},
{
"title": "How do you check web storage browser support?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448750198848769313",
"level": "basic",
"theme": "web storage, browser support, JavaScript",
"text": "### How do you check web storage browser support?\n\nTo check if a browser supports web storage, you can check if `localStorage` or `sessionStorage` is available:\n\n```javascript\nif (typeof(Storage) !== 'undefined') {\n // Web storage is supported\n} else {\n // Web storage is not supported\n}\n```",
"link": "#how-do-you-check-web-storage-browser-support"
},
{
"title": "Why do you need web storage?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448934582965046561",
"level": "basic",
"theme": "web storage, JavaScript",
"text": "### Why do you need web storage?\n\nWeb storage allows you to store data on the client side, providing faster access to information without requiring a round-trip to the server. It helps with tasks like saving user preferences, session information, and caching data for offline use.",
"link": "#why-do-you-need-web-storage"
},
{
"title": "How Do You Receive Server-Sent Event Notifications?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7448989685881376033",
"level": "intermediate",
"theme": "Server-Sent Events, notifications, web technologies",
"text": "### How Do You Receive Server-Sent Event Notifications?\n\nTo receive Server-Sent Event (SSE) notifications, you need to create an `EventSource` object in JavaScript, which listens for events sent by the server. For example:\n\n```javascript\nconst eventSource = new EventSource('https://example.com/sse');\neventSource.onmessage = function(event) {\n console.log('New message:', event.data);\n};\n```",
"link": "#how-do-you-receive-server-sent-event-notifications"
},
{
"title": "What Is a Callback in Callback?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449011382449720608",
"level": "intermediate",
"theme": "callbacks, asynchronous programming, JavaScript",
"text": "### What Is a Callback in Callback?\n\nA 'callback in callback' refers to a situation where a function is passed as a parameter to another function, and that function in turn calls another function (callback) within it. This can lead to nested callbacks, which may result in 'callback hell' if not managed properly.",
"link": "#what-is-a-callback-in-callback"
},
{
"title": "What Is Promise Chaining in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449040289345457441",
"level": "intermediate",
"theme": "Promises, JavaScript, asynchronous programming",
"text": "### What Is Promise Chaining in JavaScript?\n\nPromise chaining allows you to chain multiple `.then()` calls to handle sequential asynchronous operations. Each `.then()` returns a new promise, enabling the next step in the chain to execute after the previous one is fulfilled.\n\n```javascript\nfetchData()\n .then(result => processData(result))\n .then(processedData => displayData(processedData))\n .catch(error => console.error(error));\n```",
"link": "#what-is-promise-chaining-in-javascript"
},
{
"title": "What Are the Main Rules of Promise in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449057432086580513",
"level": "intermediate",
"theme": "Promises, JavaScript",
"text": "### What Are the Main Rules of Promise in JavaScript?\n\nThe main rules of Promises in JavaScript are:\n1. A promise can be in one of three states: pending, fulfilled, or rejected.\n2. A promise can only transition from pending to fulfilled or rejected, and cannot change back.\n3. You can attach `.then()` to handle success and `.catch()` for errors.",
"link": "#what-are-the-main-rules-of-promise-in-javascript"
},
{
"title": "What Are the Events Available for Server-Sent Events?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449065499603881248",
"level": "intermediate",
"theme": "Server-Sent Events, web technologies",
"text": "### What Are the Events Available for Server-Sent Events?\n\nServer-Sent Events (SSE) support several event types, including:\n- `message`: The default event for incoming data.\n- `open`: Fired when the connection to the server is established.\n- `error`: Fired when there is an error with the connection.",
"link": "#what-are-the-events-available-for-server-sent-events"
},
{
"title": "How Do You Check Browser Support for Server-Sent Events?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449149383142018336",
"level": "basic",
"theme": "Server-Sent Events, browser support",
"text": "### How Do You Check Browser Support for Server-Sent Events?\n\nTo check if the browser supports Server-Sent Events, you can check for the `EventSource` object:\n\n```javascript\nif (typeof(EventSource) !== 'undefined') {\n // SSE is supported\n} else {\n // SSE is not supported\n}\n```",
"link": "#how-do-you-check-browser-support-for-server-sent-events"
},
{
"title": "What Is `Promise.all` in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449321820743847200",
"level": "intermediate",
"theme": "Promises, JavaScript, asynchronous programming",
"text": "### What Is `Promise.all` in JavaScript?\n\n`Promise.all` is a method that accepts an array of promises and returns a single promise that resolves when all the promises in the array are resolved. If any of the promises reject, the returned promise will reject immediately.\n\n```javascript\nPromise.all([promise1, promise2, promise3])\n .then(results => console.log(results))\n .catch(error => console.error(error));\n```",
"link": "#what-is-promise-all-in-javascript"
},
{
"title": "What Is the Purpose of the `race` Method in Promises?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449363438461144353",
"level": "intermediate",
"theme": "Promises, JavaScript, asynchronous programming",
"text": "### What Is the Purpose of the `race` Method in Promises?\n\nThe `Promise.race()` method returns a promise that resolves or rejects as soon as one of the promises in the iterable resolves or rejects. It is useful when you need to wait for the first promise to settle.\n\n```javascript\nPromise.race([promise1, promise2, promise3])\n .then(result => console.log(result))\n .catch(error => console.error(error));\n```",
"link": "#what-is-the-purpose-of-the-race-method-in-promises"
},
{
"title": "What Is Strict Mode in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449392707455175968",
"level": "intermediate",
"theme": "JavaScript, strict mode",
"text": "### What Is Strict Mode in JavaScript?\n\nStrict mode is a way to opt in to a restricted version of JavaScript. It helps catch common coding mistakes and prevents the use of certain features that can lead to bugs, such as using undeclared variables.\n\n```javascript\n'use strict';\nvar x = 3.14; // Error in strict mode: assignment to undeclared variable\n```",
"link": "#what-is-strict-mode-in-javascript"
},
{
"title": "What Is the Purpose of Double Exclamation in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449429710985022753",
"level": "basic",
"theme": "JavaScript, type coercion",
"text": "### What Is the Purpose of Double Exclamation in JavaScript?\n\nDouble exclamation (`!!`) is used to convert a value into a boolean. The first exclamation negates the value, and the second negates it again, resulting in a boolean representation of the value.\n\n```javascript\nconsole.log(!!'string'); // true\nconsole.log(!!0); // false\n```",
"link": "#what-is-the-purpose-of-double-exclamation-in-javascript"
},
{
"title": "How Do You Declare Strict Mode in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449490448533507361",
"level": "basic",
"theme": "JavaScript, strict mode",
"text": "### How Do You Declare Strict Mode in JavaScript?\n\nTo declare strict mode in JavaScript, simply add `'use strict';` at the beginning of a script or a function.\n\n```javascript\n'use strict';\n// Code here will be executed in strict mode\n```",
"link": "#how-do-you-declare-strict-mode-in-javascript"
},
{
"title": "How Do You Detect Caps Lock Key Turned On or Not?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449671849920761120",
"level": "intermediate",
"theme": "JavaScript, event handling, keyboard events",
"text": "### How Do You Detect Caps Lock Key Turned On or Not?\n\nTo detect whether Caps Lock is on, you can use the `keydown` or `keypress` event and check the `event.getModifierState('CapsLock')` property.\n\n```javascript\ndocument.addEventListener('keydown', function(event) {\n if (event.getModifierState('CapsLock')) {\n console.log('Caps Lock is on');\n }\n});\n```",
"link": "#how-do-you-detect-caps-lock-key-turned-on-or-not"
},
{
"title": "How Do You Access History in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449732288268487969",
"level": "basic",
"theme": "JavaScript, history API",
"text": "### How Do You Access History in JavaScript?\n\nYou can access the browser history using the `window.history` object. This allows you to manipulate the session history (navigate, go back, forward, etc.).\n\n```javascript\nwindow.history.back(); // Go back to the previous page\nwindow.history.forward(); // Go forward in history\n```",
"link": "#how-do-you-access-history-in-javascript"
},
{
"title": "What Is the Difference Between `window` and `document` in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449755076182215968",
"level": "basic",
"theme": "JavaScript, DOM",
"text": "### What Is the Difference Between `window` and `document` in JavaScript?\n\n`window` represents the browser window and is the global object in the browser's JavaScript environment. `document`, on the other hand, represents the HTML document loaded in the browser, allowing interaction with the DOM.\n\n```javascript\nconsole.log(window); // Browser window\nconsole.log(document); // HTML document\n```",
"link": "#what-is-the-difference-between-window-and-document-in-javascript"
},
{
"title": "What Is the Purpose of Double Exclamation in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449813378895203617",
"level": "basic",
"theme": "JavaScript, type coercion",
"text": "### What Is the Purpose of Double Exclamation in JavaScript?\n\nDouble exclamation (`!!`) is used to convert a value to a boolean. The first negation converts it to a boolean, and the second negation reverts it to the correct boolean value.\n\n```javascript\nconsole.log(!!'text'); // true\nconsole.log(!!null); // false\n```",
"link": "#what-is-the-purpose-of-double-exclamation-in-javascript"
},
{
"title": "What Is `eval` in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449833381975559446",
"level": "intermediate",
"theme": "JavaScript, security",
"text": "### What Is `eval` in JavaScript?\n\n`eval()` is a JavaScript function that evaluates a string of JavaScript code. It is generally discouraged due to security risks such as code injection vulnerabilities.\n\n```javascript\neval('console.log(\"Hello, World!\")'); // Logs 'Hello, World!'\n```",
"link": "#what-is-eval-in-javascript"
},
{
"title": "What Is the `null` Value in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7449876086793489696",
"level": "basic",
"theme": "JavaScript, data types",
"text": "### What Is the `null` Value in JavaScript?\n\n`null` is a primitive value that represents the intentional absence of any object value. It is used to indicate that a variable is empty or uninitialized.\n\n```javascript\nlet x = null;\nconsole.log(x); // null\n```",
"link": "#what-is-the-null-value-in-javascript"
},
{
"title": "What Is the `undefined` Property in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450179747931278624",
"level": "basic",
"theme": "JavaScript, data types",
"text": "### What Is the `undefined` Property in JavaScript?\n\n`undefined` is a primitive value that is automatically assigned to variables that are declared but not initialized. It represents the absence of a defined value.\n\n```javascript\nlet x;\nconsole.log(x); // undefined\n```",
"link": "#what-is-the-undefined-property-in-javascript"
},
{
"title": "What Is the Purpose of the `delete` Operator in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450258222222560544",
"level": "intermediate",
"theme": "JavaScript, operators",
"text": "### What Is the Purpose of the `delete` Operator in JavaScript?\n\nThe `delete` operator is used to remove a property from an object or an element from an array.\n\n```javascript\nlet obj = { name: 'John', age: 30 };\ndelete obj.age;\nconsole.log(obj); // { name: 'John' }\n```",
"link": "#what-is-the-purpose-of-the-delete-operator-in-javascript"
},
{
"title": "What Is the `typeof` Operator in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450568773712497953",
"level": "basic",
"theme": "JavaScript, operators",
"text": "### What Is the `typeof` Operator in JavaScript?\n\nThe `typeof` operator returns a string indicating the type of the unevaluated operand. It is commonly used to check the type of variables or expressions.\n\n```javascript\nconsole.log(typeof 'Hello'); // string\nconsole.log(typeof 123); // number\n```",
"link": "#what-is-the-typeof-operator-in-javascript"
},
{
"title": "What Is `isNaN` in JavaScript?",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450774214459673888",
"level": "basic",
"theme": "JavaScript, type checking",
"text": "### What Is `isNaN` in JavaScript?\n\n`isNaN()` is a function that checks whether a value is NaN (Not-a-Number). It returns `true` if the value is NaN, and `false` otherwise.\n\n```javascript\nconsole.log(isNaN(123)); // false\nconsole.log(isNaN('Hello')); // true\n```",
"link": "#what-is-isnan-in-javascript"
},
{
"title": "What are the differences between undeclared and undefined variables",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450925531370884385",
"level": "basic",
"theme": "JavaScript, variables",
"text": "### What are the differences between undeclared and undefined variables?\n\nAn undeclared variable is one that has not been declared using `var`, `let`, or `const`. An undefined variable is one that has been declared but not assigned a value.",
"link": "#what-are-the-differences-between-undeclared-and-undefined-variables"
},
{
"title": "What are global variables",
"url": "https://www.tiktok.com/@jsmentoring/photo/7450838618257575201",
"level": "basic",
"theme": "JavaScript, variables",
"text": "### What are global variables?\n\nGlobal variables are variables that are declared outside of any function and are accessible from any part of the code.",
"link": "#what-are-global-variables"
},
{
"title": "What are the problems with global variables",
"url": "https://www.tiktok.com/@jsmentoring/photo/7451163740982070561",
"level": "intermediate",
"theme": "JavaScript, best practices",
"text": "### What are the problems with global variables?\n\nGlobal variables can cause issues like name collisions, difficulty in debugging, and unintended side effects. It's recommended to limit the use of global variables.",
"link": "#what-are-the-problems-with-global-variables"
},
{
"title": "What is NaN property",
"url": "https://www.tiktok.com/@jsmentoring/photo/7451255958266760480",
"level": "basic",
"theme": "JavaScript, type checking",
"text": "### What is NaN property?\n\n`NaN` (Not-a-Number) is a special value in JavaScript that represents an invalid or undefined numerical result, such as the result of dividing 0 by 0.",
"link": "#what-is-nan-property"
},
{
"title": "What is the purpose of isFinite function",
"url": "",
"level": "intermediate",
"theme": "JavaScript, type checking",
"text": "### What is the purpose of isFinite function?\n\n`isFinite()` is used to check if a value is a finite number. It returns `true` if the value is a finite number, and `false` otherwise.",
"link": "#what-is-the-purpose-of-isfinite-function"
},
{
"title": "What is an event flow",
"url": "https://www.tiktok.com/@jsmentoring/photo/7451321489682468128",
"level": "intermediate",
"theme": "JavaScript, events",
"text": "### What is an event flow?\n\nEvent flow in JavaScript refers to the order in which events are propagated through the DOM. It consists of three phases: capturing phase, target phase, and bubbling phase.",
"link": "#what-is-an-event-flow"
},
{
"title": "What is event bubbling",
"url": "https://www.tiktok.com/@jsmentoring/photo/7451597511862603040",
"level": "basic",
"theme": "JavaScript, events",
"text": "### What is event bubbling?\n\nEvent bubbling is the process where an event triggered on a child element is propagated up to its parent elements. It is the default behavior for most events in JavaScript.",
"link": "#what-is-event-bubbling"
},
{
"link": "#can-i-add-getters-and-setters-using-defineproperty-method",
"title": "Can I add getters and setters using defineProperty method",
"url": "",
"level": "basic",
"theme": "JavaScript, objects",
"text": "### Can I add getters and setters using defineProperty method?\n\nYes, you can add getters and setters using `Object.defineProperty()`. This allows you to define custom getter and setter methods for specific properties.\n\nExample:\n\n```javascript\nconst person = {};\nObject.defineProperty(person, 'name', {\n get() { return this._name; },\n set(value) { this._name = value.toUpperCase(); }\n});\nperson.name = 'John';\nconsole.log(person.name); // 'JOHN'\n```"
},
{
"link": "#can-i-avoid-using-postmessages-completely",
"title": "Can I avoid using postMessages completely",
"url": "",
"level": "advanced",
"theme": "JavaScript, Security",
"text": "### Can I avoid using postMessages completely?\n\nWhile `postMessage` is a useful API for cross-origin communication, alternatives like `localStorage`, `cookies`, or server-side messaging (e.g., WebSockets) can be used depending on the use case. Avoiding `postMessage` may increase security in certain scenarios."
},
{
"link": "#can-i-redeclare-let-and-const-variables",
"title": "Can I redeclare let and const variables",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Variables",
"text": "### Can I redeclare `let` and `const` variables?\n\nNo, you cannot redeclare `let` and `const` variables in the same scope. The `let` and `const` declarations are block-scoped, and attempting to redeclare them will result in a syntax error.\n\nExample:\n\n```javascript\nlet x = 10;\nlet x = 20; // Error: Cannot redeclare block-scoped variable 'x'\n```"
},
{
"link": "#can-i-use-reserved-words-as-identifiers",
"title": "Can I use reserved words as identifiers",
"url": "https://www.tiktok.com/@jsmentoring/photo/7457212868161850657",
"level": "basic",
"theme": "JavaScript, syntax",
"text": "### Can I use reserved words as identifiers?\n\nNo, you cannot use reserved words (such as `let`, `class`, `function`, etc.) as identifiers (variable names, function names, etc.) in JavaScript.\n\nExample:\n\n```javascript\nlet let = 5; // SyntaxError: Unexpected token 'let'\n```"
},
{
"link": "#can-we-define-properties-for-functions",
"title": "Can we define properties for functions",
"url": "https://www.tiktok.com/@jsmentoring/photo/7456170349391023393",
"level": "basic",
"theme": "JavaScript, functions",
"text": "### Can we define properties for functions?\n\nYes, functions in JavaScript are objects, so you can define properties for them.\n\n```javascript\nfunction myFunc() {}\nmyFunc.property = 'value';\nconsole.log(myFunc.property); // 'value'\n```"
},
{
"link": "#can-you-apply-chaining-on-conditional-operator",
"title": "Can you apply chaining on conditional operator",
"url": "https://www.tiktok.com/@jsmentoring/photo/7458016862446570785",
"level": "basic",
"theme": "JavaScript, operators",
"text": "### Can you apply chaining on conditional operator?\n\nYes, you can chain multiple conditional operators together to evaluate multiple conditions in a single expression.\n\nExample:\n\n```javascript\nconst result = (age >= 18) ? 'Adult' : (age >= 13) ? 'Teen' : 'Child';\n```"
},
{
"link": "#can-you-give-an-example-of-when-you-really-need-a-semicolon",
"title": "Can you give an example of when you really need a semicolon",
"url": "https://www.tiktok.com/@jsmentoring/photo/7457679188732939553",
"level": "basic",
"theme": "JavaScript, syntax",
"text": "### Can you give an example of when you really need a semicolon?\n\nSemicolons are generally optional in JavaScript, but there are situations where they are required. For example, when returning an object from a function on the same line.\n\nExample:\n\n```javascript\nreturn { key: 'value' }; // Requires semicolon\n```"
},
{
"link": "#can-you-write-a-random-integers-function-to-print-integers-within-a-range",
"title": "Can you write a random integers function to print integers within a range",
"url": "https://www.tiktok.com/@jsmentoring/photo/7456920292397518112",
"level": "basic",
"theme": "JavaScript, math",
"text": "### Can you write a random integers function to print integers within a range?\n\nYou can create a function that generates random integers within a specified range.\n\nExample:\n\n```javascript\nfunction getRandomInt(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nconsole.log(getRandomInt(1, 100)); // Generates a random integer between 1 and 100\n```"
},
{
"link": "#check-for-anagrams",
"title": "Check for Anagrams",
"url": "https://www.tiktok.com/@jsmentoring/video/7458386392272473377",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Check for Anagrams\n\nAn anagram is a word or phrase formed by rearranging the letters of another, using all the original letters exactly once.\n\n#### Algorithm:\n1. Remove any non-alphanumeric characters and convert both strings to lowercase.\n2. Check if the lengths of the two strings are the same. If not, they cannot be anagrams.\n3. Count the frequency of each character in the first string.\n4. Compare the character counts with the second string by decrementing the counts. If any count becomes negative or mismatches, the strings are not anagrams.\n\n#### Example:\n```javascript\nfunction areAnagrams(str1, str2) {\n // Normalize the strings: remove non-alphanumeric characters and convert to lowercase\n const normalize = str => str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();\n const s1 = normalize(str1);\n const s2 = normalize(str2);\n\n if (s1.length !== s2.length) {\n return false; // Different lengths mean they can't be anagrams\n }\n\n const charCount = {};\n\n // Count characters in the first string\n for (const char of s1) {\n charCount[char] = (charCount[char] || 0) + 1;\n }\n\n // Compare characters with the second string\n for (const char of s2) {\n if (!charCount[char]) {\n return false; // Character mismatch\n }\n charCount[char]--;\n }\n\n return true; // Strings are anagrams\n}\n\n// Example usage\nconsole.log(areAnagrams(\"listen\", \"silent\")); // Output: true\nconsole.log(areAnagrams(\"hello\", \"world\")); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the strings."
},
{
"link": "#check-if-a-number-is-perfect",
"title": "Check if a Number is Perfect",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Math, Algorithm",
"text": "### Check if a Number is Perfect\n\nA perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself).\n\n#### Algorithm:\n1. Initialize a variable to store the sum of divisors.\n2. Iterate from 1 to half of the number.\n3. For each divisor, add it to the sum.\n4. If the sum equals the original number, return `true`, otherwise return `false`.\n\n#### Example:\n```javascript\nfunction isPerfectNumber(num) {\n let sum = 0;\n for (let i = 1; i <= num / 2; i++) {\n if (num % i === 0) sum += i;\n }\n return sum === num;\n}\n\n// Example usage\nconsole.log(isPerfectNumber(28)); // Output: true\nconsole.log(isPerfectNumber(6)); // Output: true\nconsole.log(isPerfectNumber(10)); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the number being checked."
},
{
"link": "#check-if-a-number-is-prime",
"title": "Check if a Number is Prime",
"url": "",
"level": "basic",
"theme": "JavaScript, Numbers, Algorithm",
"text": "### Check if a Number is Prime\n\nTo check if a number is prime, verify that it is greater than 1 and divisible only by 1 and itself.\n\n#### Algorithm:\n1. Check if the number is less than or equal to 1; if so, return false.\n2. Iterate through numbers from 2 to the square root of the number.\n3. If the number is divisible by any of these, return false.\n4. If no divisors are found, return true.\n\n#### Example:\n```javascript\nfunction isPrime(num) {\n if (num <= 1) {\n return false;\n }\n\n for (let i = 2; i <= Math.sqrt(num); i++) {\n if (num % i === 0) {\n return false;\n }\n }\n\n return true;\n}\n\n// Example usage\nconsole.log(isPrime(7)); // Output: true\nconsole.log(isPrime(10)); // Output: false\n```\n\nThis method has a time complexity of O(sqrt(n)), where n is the number being checked."
},
{
"link": "#check-if-a-string-is-a-palindrome",
"title": "Check if a String is a Palindrome",
"url": "https://www.tiktok.com/@jsmentoring/video/7458413373315681569",
"level": "basic",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Check if a String is a Palindrome\n\nA palindrome is a word, phrase, or sequence that reads the same backward as forward.\n\n#### Algorithm:\n1. Remove all non-alphanumeric characters and convert the string to lowercase to handle case sensitivity.\n2. Use two pointers: one starting at the beginning and the other at the end of the string.\n3. Compare characters at the two pointers. If they differ, the string is not a palindrome.\n4. Move the pointers closer to the center and repeat the comparison.\n5. If all characters match, the string is a palindrome.\n\n#### Example:\n```javascript\nfunction isPalindrome(str) {\n // Normalize the string: remove non-alphanumeric characters and convert to lowercase\n const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();\n\n let left = 0;\n let right = cleanStr.length - 1;\n\n while (left < right) {\n if (cleanStr[left] !== cleanStr[right]) {\n return false; // Not a palindrome\n }\n left++;\n right--;\n }\n\n return true; // It's a palindrome\n}\n\n// Example usage\nconsole.log(isPalindrome(\"A man, a plan, a canal, Panama\")); // Output: true\nconsole.log(isPalindrome(\"hello\")); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#check-if-a-string-is-palindromic-permutation",
"title": "Check if a String is a Palindromic Permutation",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Check if a String is a Palindromic Permutation\n\nTo check if a string is a permutation of a palindrome, the string's characters must appear in pairs (except possibly one character for odd-length strings).\n\n#### Algorithm:\n1. Count the frequency of each character in the string.\n2. Check how many characters have an odd frequency.\n3. If more than one character has an odd frequency, return false; otherwise, return true.\n\n#### Example:\n```javascript\nfunction isPalindromicPermutation(str) {\n const freqMap = {};\n\n for (const char of str) {\n freqMap[char] = (freqMap[char] || 0) + 1;\n }\n\n let oddCount = 0;\n for (const count of Object.values(freqMap)) {\n if (count % 2 !== 0) {\n oddCount += 1;\n }\n }\n\n return oddCount <= 1;\n}\n\n// Example usage\nconsole.log(isPalindromicPermutation(\"civic\")); // Output: true\nconsole.log(isPalindromicPermutation(\"ivicc\")); // Output: true\nconsole.log(isPalindromicPermutation(\"hello\")); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#check-if-a-string-is-rotated",
"title": "Check if a String is Rotated",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Check if a String is Rotated\n\nTo check if one string is a rotation of another, concatenate the first string with itself and check if the second string is a substring of the result.\n\n#### Algorithm:\n1. Concatenate the first string with itself.\n2. Check if the second string is a substring of the concatenated string.\n3. If it is, return `true`; otherwise, return `false`.\n\n#### Example:\n```javascript\nfunction isRotated(str1, str2) {\n if (str1.length !== str2.length) return false;\n return (str1 + str1).includes(str2);\n}\n\n// Example usage\nconsole.log(isRotated('abcde', 'cdeab')); // Output: true\nconsole.log(isRotated('abcde', 'abced')); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the strings."
},
{
"link": "#check-if-an-array-is-sorted",
"title": "Check if an Array is Sorted",
"url": "",
"level": "basic",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Check if an Array is Sorted\n\nTo check if an array is sorted, compare each element with the next one to ensure it is in the correct order.\n\n#### Algorithm:\n1. Iterate through the array and compare each element with the next.\n2. If any element is greater than the next one, the array is not sorted.\n3. If no such element is found, return true; otherwise, return false.\n\n#### Example:\n```javascript\nfunction isArraySorted(arr) {\n for (let i = 0; i < arr.length - 1; i++) {\n if (arr[i] > arr[i + 1]) {\n return false;\n }\n }\n return true;\n}\n\n// Example usage\nconsole.log(isArraySorted([1, 2, 3, 4])); // Output: true\nconsole.log(isArraySorted([1, 3, 2, 4])); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#check-if-two-strings-are-palindromes-of-each-other",
"title": "Check if Two Strings Are Palindromes of Each Other",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Check if Two Strings Are Palindromes of Each Other\n\nTo check if two strings are palindromes of each other, reverse one string and compare it with the other string.\n\n#### Algorithm:\n1. Reverse one of the strings.\n2. Compare the reversed string with the other string.\n3. If they are equal, return true, indicating that they are palindromes of each other.\n\n#### Example:\n```javascript\nfunction arePalindromes(str1, str2) {\n return str1 === str2.split('').reverse().join('');\n}\n\n// Example usage\nconsole.log(arePalindromes('abcd', 'dcba')); // Output: true\nconsole.log(arePalindromes('abc', 'def')); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#count-the-number-of-1-bits-in-a-number",
"title": "Count the Number of 1 Bits in a Number",
"url": "",
"level": "basic",
"theme": "JavaScript, Bit Manipulation, Algorithm",
"text": "### Count the Number of 1 Bits in a Number\n\nTo count the number of 1 bits in a number, use bitwise operations. The idea is to repeatedly clear the least significant 1 bit and count how many times this operation is performed.\n\n#### Algorithm:\n1. Initialize a counter variable to 0.\n2. Repeatedly perform the operation `n & (n - 1)` to clear the least significant 1 bit of `n`.\n3. Increment the counter for each operation.\n4. Return the counter.\n\n#### Example:\n```javascript\nfunction hammingWeight(n) {\n let count = 0;\n while (n !== 0) {\n n &= (n - 1);\n count++;\n }\n return count;\n}\n\n// Example usage\nconsole.log(hammingWeight(11)); // Output: 3 (binary: 1011)\nconsole.log(hammingWeight(128)); // Output: 1 (binary: 10000000)\n```\n\nThis method has a time complexity of O(k), where k is the number of 1 bits in the number."
},
{
"link": "#count-the-occurences-of-an-element-in-an-array",
"title": "Count the Occurrences of an Element in an Array",
"url": "",
"level": "basic",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Count the Occurrences of an Element in an Array\n\nTo count the occurrences of an element in an array, iterate through the array and keep track of how many times the element appears.\n\n#### Algorithm:\n1. Initialize a counter variable to 0.\n2. Iterate through the array and check if each element matches the target element.\n3. Increment the counter for each match.\n4. Return the counter.\n\n#### Example:\n```javascript\nfunction countOccurrences(arr, elem) {\n let count = 0;\n\n for (const item of arr) {\n if (item === elem) {\n count++;\n }\n }\n\n return count;\n}\n\n// Example usage\nconsole.log(countOccurrences([1, 2, 3, 2, 4], 2)); // Output: 2\nconsole.log(countOccurrences([\"apple\", \"banana\", \"apple\"], \"apple\")); // Output: 2\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#count-vowels-in-a-string",
"title": "Count Vowels in a String",
"url": "",
"level": "basic",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Count Vowels in a String\n\nTo count the vowels in a string, iterate through the string and check if each character is a vowel.\n\n#### Algorithm:\n1. Normalize the string by converting it to lowercase to handle case insensitivity.\n2. Define a set or array containing all vowel characters (`a, e, i, o, u`).\n3. Iterate through the string and count characters that match any vowel.\n4. Return the total count of vowels.\n\n#### Example:\n```javascript\nfunction countVowels(str) {\n const vowels = new Set(['a', 'e', 'i', 'o', 'u']);\n let count = 0;\n\n for (const char of str.toLowerCase()) {\n if (vowels.has(char)) {\n count++;\n }\n }\n\n return count;\n}\n\n// Example usage\nconsole.log(countVowels(\"Hello World\")); // Output: 3\nconsole.log(countVowels(\"JavaScript is awesome!\")); // Output: 8\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#count-words-in-a-string",
"title": "Count Words in a String",
"url": "",
"level": "basic",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Count Words in a String\n\nTo count the number of words in a string, split the string by spaces and count the resulting elements.\n\n#### Algorithm:\n1. Split the string by spaces into an array of words.\n2. Filter out any empty strings from the array.\n3. Return the length of the array.\n\n#### Example:\n```javascript\nfunction countWords(str) {\n return str.split(' ').filter(word => word !== '').length;\n}\n\n// Example usage\nconsole.log(countWords('Hello world, how are you?')); // Output: 5\nconsole.log(countWords(' This is a test ')); // Output: 4\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#do-all-objects-have-prototypes",
"title": "Do all objects have prototypes",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Objects",
"text": "### Do all objects have prototypes?\n\nYes, in JavaScript, all objects inherit from `Object.prototype` by default, which means they have access to its methods and properties. However, objects created with `Object.create(null)` do not have a prototype.\n\nExample:\n\n```javascript\nlet obj = {};\nconsole.log(Object.getPrototypeOf(obj)); // Output: [object Object]\n```"
},
{
"link": "#does-javascript-supports-namespace",
"title": "Does JavaScript supports namespace",
"url": "",
"level": "intermediate",
"theme": "JavaScript, namespaces",
"text": "### Does JavaScript support namespaces?\n\nJavaScript does not have a built-in `namespace` feature like some other programming languages. However, you can create a namespace-like structure using objects or modules.\n\nExample using objects as namespaces:\n\n```javascript\nconst MyNamespace = {\n myFunction: function() { console.log('Hello!'); },\n myVariable: 42\n};\nMyNamespace.myFunction(); // 'Hello!'\n```"
},
{
"link": "#does-javascript-uses-mixins",
"title": "Does javascript uses mixins",
"url": "",
"level": "advanced",
"theme": "JavaScript, Object-Oriented Programming",
"text": "### Does JavaScript use mixins?\n\nYes, JavaScript can implement mixins, which are objects that provide methods to other objects. A mixin is a way to reuse functionality across different objects without using inheritance.\n\nExample:\n\n```javascript\nlet mixin = {\n greet() { console.log('Hello!'); }\n};\n\nlet obj = Object.assign({}, mixin);\nobj.greet(); // Output: 'Hello!'\n```"
},
{
"link": "#does-the-const-variable-make-the-value-immutable",
"title": "Does the const variable make the value immutable",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Variables",
"text": "### Does the `const` variable make the value immutable?\n\nNo, `const` only ensures that the variable identifier cannot be reassigned. It does not make the value immutable. If the value is an object or array, its properties or elements can still be modified.\n\nExample:\n\n```javascript\nconst arr = [1, 2, 3];\narr.push(4); // Works fine\narr = [4, 5, 6]; // Error: Assignment to constant variable\n```"
},
{
"link": "#find-all-pairs-in-an-array-with-a-given-sum",
"title": "Find All Pairs in an Array with a Given Sum",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find All Pairs in an Array with a Given Sum\n\nTo find all pairs that sum to a specific target, use a hash set to track the complements of each element.\n\n#### Algorithm:\n1. Initialize an empty set to store elements.\n2. Iterate through the array and calculate the complement (target - current element).\n3. If the complement exists in the set, add the pair to the result.\n4. Otherwise, add the current element to the set.\n5. Return the list of pairs.\n\n#### Example:\n```javascript\nfunction findPairsWithSum(arr, target) {\n const seen = new Set(), pairs = [];\n for (let num of arr) {\n const complement = target - num;\n if (seen.has(complement)) {\n pairs.push([complement, num]);\n }\n seen.add(num);\n }\n return pairs;\n}\n\n// Example usage\nconsole.log(findPairsWithSum([1, 2, 3, 4, 5], 5)); // Output: [[2, 3], [1, 4]]\nconsole.log(findPairsWithSum([10, 15, 3, 7], 17)); // Output: [[10, 7]]\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-all-pairs-that-sum-to-a-target",
"title": "Find All Pairs That Sum to a Target",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find All Pairs That Sum to a Target\n\nTo find all pairs of numbers in an array that sum up to a target value, use a hash set to track the numbers seen so far and check if the complement of each number exists in the set.\n\n#### Algorithm:\n1. Initialize an empty set to store the numbers.\n2. Iterate through the array and for each number, check if the complement (target - number) is already in the set.\n3. If the complement exists, add the pair to the result array.\n4. If the complement doesn't exist, add the current number to the set.\n\n#### Example:\n```javascript\nfunction findPairs(arr, target) {\n let pairs = [];\n let seen = new Set();\n for (let num of arr) {\n let complement = target - num;\n if (seen.has(complement)) {\n pairs.push([complement, num]);\n }\n seen.add(num);\n }\n return pairs;\n}\n\n// Example usage\nconsole.log(findPairs([1, 2, 3, 4, 5], 5)); // Output: [[2, 3], [1, 4]]\nconsole.log(findPairs([1, 3, 2, 4, 5], 6)); // Output: [[1, 5], [2, 4]]\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-all-pairs-with-sum",
"title": "Find All Pairs with a Given Sum",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find All Pairs with a Given Sum\n\nTo find all pairs in an array that sum up to a specific target value, use a hash set to track the numbers that can form pairs.\n\n#### Algorithm:\n1. Initialize an empty set to store numbers.\n2. Iterate through the array and for each element, check if the complement (target - current element) is in the set.\n3. If the complement exists, add the pair to the result array.\n4. If not, add the current element to the set.\n5. Return the array of pairs.\n\n#### Example:\n```javascript\nfunction findPairs(arr, target) {\n const pairs = [];\n const seen = new Set();\n for (let num of arr) {\n const complement = target - num;\n if (seen.has(complement)) {\n pairs.push([complement, num]);\n }\n seen.add(num);\n }\n return pairs;\n}\n\n// Example usage\nconsole.log(findPairs([1, 2, 3, 4, 5], 5)); // Output: [[1, 4], [2, 3]]\nconsole.log(findPairs([10, 15, 3, 7], 17)); // Output: [[10, 7]]\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-all-prime-numbers-in-a-range",
"title": "Find All Prime Numbers in a Range",
"url": "",
"level": "basic",
"theme": "JavaScript, Math, Algorithm",
"text": "### Find All Prime Numbers in a Range\n\nTo find all prime numbers within a given range, use the Sieve of Eratosthenes algorithm to efficiently find primes.\n\n#### Algorithm:\n1. Create a boolean array `isPrime` where each index represents a number.\n2. Set all values to `true` except for 0 and 1.\n3. Starting from 2, mark all multiples of each prime as `false`.\n4. Return the indices that are still `true` as the prime numbers.\n\n#### Example:\n```javascript\nfunction sieveOfEratosthenes(limit) {\n let isPrime = new Array(limit + 1).fill(true);\n isPrime[0] = isPrime[1] = false;\n for (let i = 2; i * i <= limit; i++) {\n if (isPrime[i]) {\n for (let j = i * i; j <= limit; j += i) {\n isPrime[j] = false;\n }\n }\n }\n return isPrime.map((prime, index) => prime ? index : -1).filter(index => index !== -1);\n}\n\n// Example usage\nconsole.log(sieveOfEratosthenes(20)); // Output: [2, 3, 5, 7, 11, 13, 17, 19]\n```\n\nThis method has a time complexity of O(n log log n), where n is the limit."
},
{
"link": "#find-all-prime-numbers-in-an-array",
"title": "Find All Prime Numbers in an Array",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find All Prime Numbers in an Array\n\nTo find all prime numbers in an array, check each number in the array to see if it is prime.\n\n#### Algorithm:\n1. Define a helper function `isPrime` to check if a number is prime.\n2. Iterate through the array, calling `isPrime` on each element.\n3. Collect the prime numbers and return them.\n\n#### Example:\n```javascript\nfunction isPrime(num) {\n if (num <= 1) return false;\n for (let i = 2; i <= Math.sqrt(num); i++) {\n if (num % i === 0) return false;\n }\n return true;\n}\n\nfunction findPrimes(arr) {\n return arr.filter(isPrime);\n}\n\n// Example usage\nconsole.log(findPrimes([1, 2, 3, 4, 5, 6])); // Output: [2, 3, 5]\nconsole.log(findPrimes([10, 15, 23, 30])); // Output: [23]\n```\n\nThis method has a time complexity of O(n * sqrt(m)), where n is the length of the array and m is the largest number in the array."
},
{
"link": "#find-all-subsets-of-an-array",
"title": "Find All Subsets of an Array",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find All Subsets of an Array\n\nTo find all subsets of an array, use a bitwise approach. Each element can either be included or excluded from a subset, so there are `2^n` possible subsets.\n\n#### Algorithm:\n1. Initialize an empty array to store the subsets.\n2. Iterate over the range from 0 to `2^n - 1`.\n3. For each number in the range, use its binary representation to decide which elements to include in the subset.\n4. Return the array of subsets.\n\n#### Example:\n```javascript\nfunction getSubsets(arr) {\n let subsets = [];\n let n = arr.length;\n for (let i = 0; i < (1 << n); i++) {\n let subset = [];\n for (let j = 0; j < n; j++) {\n if (i & (1 << j)) {\n subset.push(arr[j]);\n }\n }\n subsets.push(subset);\n }\n return subsets;\n}\n\n// Example usage\nconsole.log(getSubsets([1, 2, 3]));\n// Output: [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]\n```\n\nThis method has a time complexity of O(2^n), where n is the length of the array."
},
{
"link": "#find-all-substrings-of-a-string",
"title": "Find All Substrings of a String",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Find All Substrings of a String\n\nTo find all substrings of a string, iterate through all possible starting and ending indices to extract substrings.\n\n#### Algorithm:\n1. Initialize an empty array to store substrings.\n2. Iterate through the string with two nested loops: one for the starting index and one for the ending index.\n3. Extract the substring for each pair of indices and add it to the result array.\n4. Return the array of substrings.\n\n#### Example:\n```javascript\nfunction findAllSubstrings(str) {\n const substrings = [];\n for (let i = 0; i < str.length; i++) {\n for (let j = i + 1; j <= str.length; j++) {\n substrings.push(str.slice(i, j));\n }\n }\n return substrings;\n}\n\n// Example usage\nconsole.log(findAllSubstrings('abc')); // Output: ['a', 'ab', 'abc', 'b', 'bc', 'c']\nconsole.log(findAllSubstrings('hello')); // Output: ['h', 'he', 'hel', 'hell', 'hello', 'e', 'el', 'ell', 'ello', 'l', 'll', 'llo', 'l', 'lo', 'o']\n```\n\nThis method has a time complexity of O(n^2), where n is the length of the string."
},
{
"link": "#find-common-characters-in-two-strings",
"title": "Find Common Characters in Two Strings",
"url": "",
"level": "basic",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Find Common Characters in Two Strings\n\nTo find common characters in two strings, use a frequency map for each string and compare the characters.\n\n#### Algorithm:\n1. Create a frequency map for each string to count the occurrences of each character.\n2. Compare the frequency maps to find common characters.\n3. Return the list of common characters.\n\n#### Example:\n```javascript\nfunction findCommonCharacters(str1, str2) {\n const map1 = {}, map2 = {};\n for (let char of str1) map1[char] = (map1[char] || 0) + 1;\n for (let char of str2) map2[char] = (map2[char] || 0) + 1;\n const common = [];\n for (let char in map1) {\n if (map2[char]) {\n const count = Math.min(map1[char], map2[char]);\n for (let i = 0; i < count; i++) common.push(char);\n }\n }\n return common;\n}\n\n// Example usage\nconsole.log(findCommonCharacters('abc', 'cde')); // Output: ['c']\nconsole.log(findCommonCharacters('aabb', 'abcc')); // Output: ['a', 'b']\n```\n\nThis method has a time complexity of O(n + m), where n and m are the lengths of the two strings."
},
{
"link": "#find-common-prefix-in-an-array-of-strings",
"title": "Find Common Prefix in an Array of Strings",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find Common Prefix in an Array of Strings\n\nTo find the longest common prefix among an array of strings, compare characters from each string in the array.\n\n#### Algorithm:\n1. Initialize the first string in the array as the common prefix.\n2. Iterate through the rest of the strings, updating the common prefix by comparing it with each string.\n3. If no common prefix is found, return an empty string.\n4. Return the final common prefix.\n\n#### Example:\n```javascript\nfunction findCommonPrefix(arr) {\n if (arr.length === 0) return \"\";\n\n let prefix = arr[0];\n for (let i = 1; i < arr.length; i++) {\n while (arr[i].indexOf(prefix) !== 0) {\n prefix = prefix.slice(0, prefix.length - 1);\n if (prefix === \"\") return \"\";\n }\n }\n return prefix;\n}\n\n// Example usage\nconsole.log(findCommonPrefix([\"flower\", \"flow\", \"flight\"])); // Output: \"fl\"\nconsole.log(findCommonPrefix([\"dog\", \"racecar\", \"car\"])); // Output: \"\"\n```\n\nThis method has a time complexity of O(n * m), where n is the length of the array and m is the length of the longest string."
},
{
"link": "#find-duplicate-elements-in-an-array",
"title": "Find Duplicate Elements in an Array",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find Duplicate Elements in an Array\n\nTo find duplicate elements in an array, use a set to track the elements you've seen as you iterate through the array.\n\n#### Algorithm:\n1. Initialize an empty set to store unique elements.\n2. Iterate through the array and check if each element is already in the set.\n3. If it is, add it to the result array.\n4. Return the array of duplicates.\n\n#### Example:\n```javascript\nfunction findDuplicates(arr) {\n const seen = new Set();\n const duplicates = [];\n\n for (const num of arr) {\n if (seen.has(num)) {\n duplicates.push(num);\n }\n seen.add(num);\n }\n\n return duplicates;\n}\n\n// Example usage\nconsole.log(findDuplicates([1, 2, 3, 2, 4, 5, 1])); // Output: [2, 1]\nconsole.log(findDuplicates([\"apple\", \"banana\", \"apple\", \"orange\"])); // Output: [\"apple\"]\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-duplicates-in-an-array-without-extra-space",
"title": "Find Duplicates in an Array Without Extra Space",
"url": "",
"level": "advanced",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find Duplicates in an Array Without Extra Space\n\nTo find duplicates without using extra space, you can modify the array in-place.\n\n#### Algorithm:\n1. Iterate through the array and use the value of each element as an index.\n2. If the value at that index is negative, it means the element has been seen before, so it is a duplicate.\n3. If the value at that index is positive, make it negative to mark it as visited.\n4. Return the duplicates.\n\n#### Example:\n```javascript\nfunction findDuplicatesInPlace(arr) {\n const duplicates = [];\n for (let i = 0; i < arr.length; i++) {\n const absVal = Math.abs(arr[i]);\n if (arr[absVal] < 0) {\n duplicates.push(absVal);\n } else {\n arr[absVal] = -arr[absVal];\n }\n }\n return duplicates;\n}\n\n// Example usage\nconsole.log(findDuplicatesInPlace([4, 3, 2, 7, 8, 2, 3, 1])); // Output: [2, 3]\nconsole.log(findDuplicatesInPlace([1, 1, 1, 2, 2])); // Output: [1, 2]\n```\n\nThis method has a time complexity of O(n), where n is the length of the array, and does not use extra space."
},
{
"link": "#find-if-a-number-is-prime",
"title": "Find if a Number is Prime",
"url": "",
"level": "basic",
"theme": "JavaScript, Math, Algorithm",
"text": "### Find if a Number is Prime\n\nA prime number is a number greater than 1 that has no divisors other than 1 and itself. To check if a number is prime, iterate through numbers from 2 to the square root of the number.\n\n#### Algorithm:\n1. If the number is less than or equal to 1, return `false`.\n2. Check for divisibility by all numbers from 2 to the square root of the number.\n3. If any number divides evenly, return `false`. Otherwise, return `true`.\n\n#### Example:\n```javascript\nfunction isPrime(num) {\n if (num <= 1) return false;\n for (let i = 2; i <= Math.sqrt(num); i++) {\n if (num % i === 0) return false;\n }\n return true;\n}\n\n// Example usage\nconsole.log(isPrime(7)); // Output: true\nconsole.log(isPrime(10)); // Output: false\n```\n\nThis method has a time complexity of O(sqrt(n)), where n is the number being checked."
},
{
"link": "#find-if-a-string-is-rotated",
"title": "Find if a String is Rotated",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Strings, Algorithm",
"text": "### Find if a String is Rotated\n\nTo check if one string is a rotation of another, concatenate the second string with itself and check if the first string is a substring of the concatenated string.\n\n#### Algorithm:\n1. Concatenate the second string with itself.\n2. Check if the first string is a substring of the concatenated string.\n3. Return true if it is a substring, false otherwise.\n\n#### Example:\n```javascript\nfunction isRotated(str1, str2) {\n if (str1.length !== str2.length) return false;\n return (str2 + str2).includes(str1);\n}\n\n// Example usage\nconsole.log(isRotated('abc', 'bca')); // Output: true\nconsole.log(isRotated('abc', 'acb')); // Output: false\n```\n\nThis method has a time complexity of O(n), where n is the length of the string."
},
{
"link": "#find-largest-palindrome-in-an-array",
"title": "Find Largest Palindrome in an Array",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find Largest Palindrome in an Array\n\nTo find the largest palindrome in an array, iterate through the array and check each element to see if it is a palindrome.\n\n#### Algorithm:\n1. Iterate through the array and check if each element is a palindrome.\n2. Keep track of the largest palindrome found.\n3. Return the largest palindrome.\n\n#### Example:\n```javascript\nfunction isPalindrome(str) {\n return str === str.split('').reverse().join('');\n}\n\nfunction largestPalindrome(arr) {\n let largest = '';\n for (let str of arr) {\n if (isPalindrome(str) && str.length > largest.length) {\n largest = str;\n }\n }\n return largest;\n}\n\n// Example usage\nconsole.log(largestPalindrome(['madam', 'racecar', 'apple'])); // Output: 'racecar'\nconsole.log(largestPalindrome(['hello', 'world', 'civic'])); // Output: 'civic'\n```\n\nThis method has a time complexity of O(n * m), where n is the length of the array and m is the average length of the strings."
},
{
"link": "#find-missing-number-in-an-array",
"title": "Find the Missing Number in an Array",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Missing Number in an Array\n\nTo find the missing number in a sequential array, calculate the expected sum and subtract the actual sum of the array.\n\n#### Algorithm:\n1. Calculate the sum of numbers from 1 to n using the formula `n * (n + 1) / 2`.\n2. Calculate the sum of the elements in the array.\n3. Subtract the actual sum from the expected sum to find the missing number.\n\n#### Example:\n```javascript\nfunction findMissingNumber(arr) {\n const n = arr.length + 1;\n const expectedSum = (n * (n + 1)) / 2;\n const actualSum = arr.reduce((sum, num) => sum + num, 0);\n\n return expectedSum - actualSum;\n}\n\n// Example usage\nconsole.log(findMissingNumber([1, 2, 4, 5, 6])); // Output: 3\nconsole.log(findMissingNumber([3, 7, 1, 2, 8, 4, 5])); // Output: 6\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-the-average-of-an-array",
"title": "Find the Average of an Array",
"url": "",
"level": "basic",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Average of an Array\n\nTo find the average of an array, sum all the elements in the array and then divide the sum by the number of elements.\n\n#### Algorithm:\n1. Initialize a variable to store the sum of the array elements.\n2. Iterate through the array and add each element to the sum.\n3. Divide the sum by the length of the array to get the average.\n4. Return the average.\n\n#### Example:\n```javascript\nfunction findAverage(arr) {\n let sum = 0;\n for (const num of arr) {\n sum += num;\n }\n return sum / arr.length;\n}\n\n// Example usage\nconsole.log(findAverage([1, 2, 3, 4, 5])); // Output: 3\nconsole.log(findAverage([10, 20, 30])); // Output: 20\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."
},
{
"link": "#find-the-common-elements-between-two-arrays",
"title": "Find the Common Elements Between Two Arrays",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Common Elements Between Two Arrays\n\nTo find common elements between two arrays, use a set to store the elements of one array and check for intersections with the other array.\n\n#### Algorithm:\n1. Convert the first array into a set.\n2. Iterate through the second array and check if each element exists in the set.\n3. If it does, add it to the result array.\n4. Return the result array.\n\n#### Example:\n```javascript\nfunction findCommonElements(arr1, arr2) {\n const set1 = new Set(arr1);\n const common = [];\n\n for (const num of arr2) {\n if (set1.has(num)) {\n common.push(num);\n }\n }\n\n return common;\n}\n\n// Example usage\nconsole.log(findCommonElements([1, 2, 3], [3, 4, 5])); // Output: [3]\nconsole.log(findCommonElements([\"a\", \"b\", \"c\"], [\"d\", \"b\", \"e\"])); // Output: [\"b\"]\n```\n\nThis method has a time complexity of O(n + m), where n and m are the lengths of the two arrays."
},
{
"link": "#find-the-common-elements-in-two-arrays",
"title": "Find the Common Elements in Two Arrays",
"url": "",
"level": "intermediate",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Common Elements in Two Arrays\n\nTo find the common elements in two arrays, you can use a set to track elements from one array and check if they exist in the other array.\n\n#### Algorithm:\n1. Create a set from the first array to store unique elements.\n2. Iterate through the second array and check if each element is present in the set.\n3. If an element is found in both arrays, add it to the result array.\n4. Return the array of common elements.\n\n#### Example:\n```javascript\nfunction findCommonElements(arr1, arr2) {\n const set1 = new Set(arr1);\n const common = [];\n\n for (const elem of arr2) {\n if (set1.has(elem)) {\n common.push(elem);\n }\n }\n\n return common;\n}\n\n// Example usage\nconsole.log(findCommonElements([1, 2, 3], [2, 3, 4])); // Output: [2, 3]\nconsole.log(findCommonElements([\"apple\", \"banana\"], [\"banana\", \"orange\"])); // Output: [\"banana\"]\n```\n\nThis method has a time complexity of O(n + m), where n and m are the lengths of the two arrays."
},
{
"link": "#find-the-difference-between-two-arrays",
"title": "Find the Difference Between Two Arrays",
"url": "",
"level": "basic",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Difference Between Two Arrays\n\nTo find the difference between two arrays, use a set to track elements that are in one array but not the other.\n\n#### Algorithm:\n1. Convert one array into a set for efficient lookup.\n2. Iterate through the second array and add elements that are not in the set to the result array.\n3. Return the resulting array of differences.\n\n#### Example:\n```javascript\nfunction arrayDifference(arr1, arr2) {\n const set = new Set(arr1);\n return arr2.filter(item => !set.has(item));\n}\n\n// Example usage\nconsole.log(arrayDifference([1, 2, 3], [3, 4, 5])); // Output: [4, 5]\nconsole.log(arrayDifference([1, 2, 3, 4], [3, 4, 5])); // Output: [5]\n```\n\nThis method has a time complexity of O(n + m), where n and m are the lengths of the two arrays."
},
{
"link": "#find-the-duplicate-element-in-an-array",
"title": "Find the Duplicate Element in an Array",
"url": "",
"level": "basic",
"theme": "JavaScript, Arrays, Algorithm",
"text": "### Find the Duplicate Element in an Array\n\nTo find a duplicate element in an array, use a set to track the elements that have been seen. If an element is already in the set, it's a duplicate.\n\n#### Algorithm:\n1. Create an empty set to store elements.\n2. Iterate through the array.\n3. If the element is already in the set, return it as the duplicate.\n4. If the element is not in the set, add it to the set.\n\n#### Example:\n```javascript\nfunction findDuplicate(arr) {\n let seen = new Set();\n for (let num of arr) {\n if (seen.has(num)) {\n return num;\n }\n seen.add(num);\n }\n return null;\n}\n\n// Example usage\nconsole.log(findDuplicate([1, 2, 3, 4, 5, 3])); // Output: 3\nconsole.log(findDuplicate([1, 2, 3, 4, 5])); // Output: null\n```\n\nThis method has a time complexity of O(n), where n is the length of the array."