-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestions
95 lines (67 loc) · 6.28 KB
/
Questions
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
Sure! I'll explain each of the topics in English for you:
1. Differences between var, let, and const:
- `var`: Function-scoped variable, can be re-declared and updated within its scope.
- `let`: Block-scoped variable, can be updated but not re-declared within its block.
- `const`: Block-scoped constant, its value cannot be changed once assigned.
2. Hoisting:
Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their containing scope during the compilation phase. However, only the declarations are hoisted, not the initializations.
3. Primitive value and reference value:
Primitive values (e.g., numbers, strings, booleans) are immutable and directly store their value. Reference values (e.g., objects, arrays) store a reference in memory, pointing to the actual value stored elsewhere.
4. Why arrays and objects are reference types:
Arrays and objects in JavaScript are reference types because their values are not directly stored in variables. Instead, the variables store references to the memory location where the actual array or object is stored.
5. How to copy an object:
To copy an object, you can use either a shallow copy or a deep copy technique.
6. Shallow copy vs. deep copy:
- Shallow copy creates a new object, but it only copies the references to the nested objects. The nested objects are still shared between the original and copied objects.
- Deep copy creates a completely independent copy of the object and all its nested objects, so changes in the copied object won't affect the original one.
7. Functional programming and OOP:
- Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions, avoiding changing state and mutable data.
- OOP (Object-Oriented Programming) is a paradigm that organizes code into objects containing both data and behavior.
8. Difference between == and ===:
- `==` is the equality operator, which performs type coercion if the operands have different types before comparison.
- `===` is the strict equality operator, which requires both value and type to be the same for the comparison to be true.
9. Type coercion:
Type coercion is the process of converting one data type to another in JavaScript, typically done implicitly by the language.
10. Closure - concept and use cases:
A closure is a function that retains access to its lexical scope even after the function has finished executing. Use cases include private variables, data encapsulation, and creating functions with dynamic behavior.
11. Higher-Order Function (HoF):
A Higher-Order Function is a function that takes one or more functions as arguments or returns a function as its result.
12. Event bubbling:
Event bubbling is the process in which an event triggered on a nested element "bubbles up" through its ancestor elements in the DOM hierarchy, triggering their respective event handlers.
13. Event capturing:
Event capturing is the opposite of event bubbling. It involves capturing events at the highest level of the DOM hierarchy and then propagating down to the target element.
14. Classes and the super method:
Classes in JavaScript are a way to create objects with shared properties and methods. The `super` keyword is used within a subclass constructor to call the constructor of its parent class.
15. Execution context:
The execution context is a concept in JavaScript that defines the environment in which code is executed. It includes variables, scopes, and the value of the `this` keyword.
16. Differences between arrow functions and regular functions:
- Arrow functions have a shorter syntax and automatically bind `this` based on the surrounding context.
- Regular functions have their `this` value determined by how they are called.
17. Prototype in JavaScript:
The prototype is an object from which other objects inherit properties and methods. It is used to implement inheritance in JavaScript.
18. Threads:
Threads are units of execution that can run concurrently in a program, allowing for multitasking and parallel processing.
19. Event loop:
The event loop is a core part of JavaScript's concurrency model. It continuously checks the message queue for pending tasks and executes them one by one, ensuring non-blocking behavior.
20. Scope chain:
The scope chain is the order in which JavaScript searches for variables and functions in nested scopes. It enables access to variables from outer scopes.
21. Differences between bind and apply methods:
- Both methods are used to set the value of `this` in a function. `bind` returns a new function with the bound `this`, while `apply` immediately invokes the function with the specified `this` value and arguments.
22. Explanation of reduce, map, and filter:
- `reduce`: Iterates over an array, accumulating a single value based on a callback function.
- `map`: Creates a new array by applying a callback function to each element of the original array.
- `filter`: Creates a new array with elements that pass a test implemented by a callback function.
23. Philosophy of virtual DOM:
Virtual DOM is a concept used in frameworks like React to improve performance by minimizing direct manipulation of the actual DOM. It creates a lightweight copy of the DOM in memory and efficiently updates the real DOM only when necessary.
24. React component lifecycle:
The lifecycle of a React component consists of several phases, including mounting, updating, and unmounting. Each phase has lifecycle methods that can be overridden to add custom behavior.
25. Naming React hooks:
Some common React hooks are `useState`, `useEffect`, `useContext`, `useReducer`, `useCallback`, `useMemo`, etc.
26. Code splitting:
Code splitting is a technique used to divide a large JavaScript bundle into smaller chunks, which can be loaded on-demand to improve initial page load times.
27. Improving performance of React components:
- Memoization using `useMemo` and `useCallback`.
- Implementing shouldComponentUpdate or using `React.memo`.
- Avoiding unnecessary re-renders by optimizing render logic.
- Using React's built-in profiling tools to identify performance bottlenecks.
I hope these explanations help you understand the concepts better! If you have any further questions, feel free to ask.