Skip to content

Commit b441a7e

Browse files
chore: add more questions
1 parent 9c5fdb0 commit b441a7e

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

docs/callbacks.md

+20
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,23 @@ The arguments object is a collection of parameter values pass in a function. It'
340340
It helps us know the number of arguments pass in a function.
341341

342342
We can convert the arguments object into an array using the Array.prototype.slice.
343+
344+
## Create a pipe function given below
345+
346+
```js
347+
pipe(getName, uppercase, reverse)({ name: "Abhishek" }); // 'KEHSIHBA'
348+
```
349+
350+
```js
351+
function getName(input) {
352+
return input.name;
353+
}
354+
355+
function uppercase(input) {
356+
return input.toUpperCase();
357+
}
358+
359+
function reverse(input) {
360+
return input.split("").reverse().join("");
361+
}
362+
```

docs/closures.md

+24
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,27 @@ function log() {
162162
console.log(message);
163163
}
164164
```
165+
166+
## Explain the output
167+
168+
```js
169+
function outer() {
170+
let counter = 0;
171+
return function inner() {
172+
return counter++;
173+
};
174+
}
175+
176+
const bar = outer();
177+
console.log(bar());
178+
console.log(bar());
179+
180+
const baz = outer();
181+
console.log(baz());
182+
console.log(baz());
183+
184+
// 0
185+
// 1
186+
// 0
187+
// 1
188+
```

docs/prototypes.md

+13
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ if (!Object.create) {
1717
```
1818

1919
This usage of Object.create(..) is by far the most common usage, because it's the part that can be polyfilled. There's an additional; set of functionality that the standard ES5 built-in Object.create(..) provides, which is not polyfillable for pre-ES5. As such, this capability is far less commonly used.
20+
21+
## Create a speak() given below
22+
23+
```js
24+
const name = "Abhishek";
25+
name.speak(); // "Abhishek can speak"
26+
```
27+
28+
```js
29+
String.prototype.speak = function () {
30+
return `${this} can speak`;
31+
};
32+
```

0 commit comments

Comments
 (0)