diff --git a/src/data/question-groups/javascript/content/spread-operator.md b/src/data/question-groups/javascript/content/spread-operator.md new file mode 100644 index 000000000..428a1dc7b --- /dev/null +++ b/src/data/question-groups/javascript/content/spread-operator.md @@ -0,0 +1,19 @@ +The spread operator in JavaScript is represented by three dots (`...`). It allows the elements of an array or properties of an object to be expanded or "spread" into individual elements or properties. This can be useful in various contexts, such as when passing elements as function arguments, cloning arrays and objects, or merging arrays and objects. + +```js +const roadmaps = ['JavaScript', 'React', 'Node.js']; +const bestPractices = ['AWS', 'API Security']; + +const resources = [...roadmaps, ...bestPractices]; +console.log(resources); // ['JavaScript', 'React', 'Node.js', 'AWS', 'API Security'] +``` + +```js +const roadmap = { + name: 'JavaScript', + type: 'dynamic', +}; + +const roadmapClone = { ...roadmap }; // shallow copy +console.log(roadmapClone); // { name: 'JavaScript', type: 'dynamic' } +``` diff --git a/src/data/question-groups/javascript/javascript.md b/src/data/question-groups/javascript/javascript.md index 4c2ffe3b9..654c3a5cc 100644 --- a/src/data/question-groups/javascript/javascript.md +++ b/src/data/question-groups/javascript/javascript.md @@ -158,4 +158,14 @@ questions: topics: - 'Core' - 'Beginner' + - question: What is Event Capturing in JavaScript? + answer: Event capturing is the first phase of event propagation. In this phase, the event is captured by the outermost element and propagated to the inner elements. It is also known as trickling. It is the opposite of event bubbling. + topics: + - 'Core' + - 'Beginner' + - question: What is the spread operator in JavaScript? + answer: spread-operator.md + topics: + - 'Core' + - 'Intermediate' ---