Skip to content

Commit 9b7a403

Browse files
authored
Update objects-concepts.md
1 parent d3b9235 commit 9b7a403

File tree

1 file changed

+24
-65
lines changed

1 file changed

+24
-65
lines changed

challenges/objects-concepts.md

Lines changed: 24 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,11 @@
22
<a href="/README.md#this-is-a-collection-of-modern-interview-code-challenges-on-javascript-suitable-for" id="home">Home</a>
33
</div>
44

5-
## JavaScript interview code challenges on Objects - concepts
6-
7-
1. [Show the different ways of creating an object](#Q1)
8-
1. [Display all the keys of an object](#Q2)
9-
1. [Display all the values of an object](#Q3)
10-
1. [Write a function which can check if a given object is empty or not](#Q4)
11-
1. [Create an empty object which has no prototype attached to it](#Q5)
12-
1. [Show the usage of 'Object.entries' to create an object from key value pairs](#Q6)
13-
1. [Connect 2 objects so that one object is prototypically connected to the other](#Q7)
14-
1. [Create an object with getter and setter for property](#Q8)
15-
1. [Show the different types of accessor properties available for object property and write a code defining them](#Q9)
16-
1. [Show the different options available to prevent the modifications to the object](#Q10)
17-
1. [Modify the given object so that it can be used inside a for...of loop](#Q11)
18-
1. [Show the creation of Regular Expression in JavaScript](#Q12)
19-
1. [Write a polyfill for Object.create](#Q13)
20-
1. [Write a code show Optional chaining for objects and functions](#Q14)
21-
1. [Show the usage of static variable & function in a class and accessing it from the code](#Q15)
22-
1. [Write a class which uses private variable and function](#Q16)
23-
1. [Show how inheritance works in Class and the use of super keyword with working example](#Q17)
24-
1. [Show the way of using Proxy for object](#Q18)
25-
1. [Show how can we use for..of loop to iterate on a range with given start and end values in an object](#Q19)
26-
1. [Prove that private looking variable in a function is not really private specific to that object](#Q20)
27-
28-
---
29-
30-
#### Q1
31-
### Show the different ways of creating an object
5+
<h2 align="center">JavaScript challenges on Objects - concepts</h2>
6+
7+
<br>
8+
9+
### Q. Show the different ways of creating an object
3210

3311
- Object can be created using Object constuctor
3412
- Object can also be created using Object literal form
@@ -68,8 +46,7 @@ const object = new Obj('key', 'value');
6846

6947
<br />
7048

71-
#### Q2
72-
### Display all the keys of an object
49+
### Q. Display all the keys of an object
7350

7451
- The keys of an object can be obtained using `Object.keys`
7552

@@ -105,8 +82,7 @@ Object.keys(obj).forEach((key) => {
10582

10683
<br />
10784

108-
#### Q3
109-
### Display all the values of an object
85+
### Q. Display all the values of an object
11086

11187
- The values of an object can be obtained using `Object.values` which returns an array of values
11288

@@ -140,8 +116,7 @@ for(let key in obj){
140116

141117
<br />
142118

143-
#### Q4
144-
### Write a function which can check if a given object is empty or not
119+
### Q. Write a function which can check if a given object is empty or not
145120

146121
- Object is empty if it has no keys
147122
- Few objects such as `Date` object does not have any keys but still are not empty. Hence additional check can be implemented to verify the stringification of the object is also empty
@@ -163,8 +138,7 @@ function isObjectEmpty(obj){
163138

164139
<br />
165140

166-
#### Q5
167-
### Create an empty object which has no prototype attached to it
141+
### Q. Create an empty object which has no prototype attached to it
168142

169143
- Objects created in JavaScript will have a prototype object on it connected to other object or `Object`
170144
- Object constructor can be used to create such an empty object
@@ -178,8 +152,7 @@ const obj = Object.create(null);
178152

179153
<br />
180154

181-
#### Q6
182-
### Show the usage of 'Object.entries' to create an object from key value pairs
155+
### Q. Show the usage of 'Object.entries' to create an object from key value pairs
183156

184157
- The key value pairs can be directly converted to object using `entries` method of Object
185158

@@ -198,8 +171,7 @@ const obj = Object.fromEntries(map);
198171

199172
<br />
200173

201-
#### Q7
202-
### Connect 2 objects so that one object is prototypically connected to the other
174+
### Q. Connect 2 objects so that one object is prototypically connected to the other
203175

204176
- Objects in JavaScript are connected its prototype and is accessible for objects getPrototypeOf or `__proto__`
205177
- `setPrototypeOf` is used to set the prototype of the object
@@ -224,8 +196,7 @@ The lookup happens at the object level initially and if the key is not found, pr
224196

225197
<br />
226198

227-
#### Q8
228-
### Create an object with getter and setter for property
199+
### Q. Create an object with getter and setter for property
229200

230201
- `getter` and `setter` on the properties of object can be used to control the read and write behavior
231202

@@ -251,8 +222,7 @@ If the `this.data` is accessed directly, the function will call itself infinitel
251222

252223
<br />
253224

254-
#### Q9
255-
### Show the different types of accessor properties available for object property and write a code defining them
225+
### Q. Show the different types of accessor properties available for object property and write a code defining them
256226

257227
- `value` accessor is used to set the value of the property
258228
- `writable` accessor is used to set if the property can be modified or not
@@ -278,8 +248,7 @@ Except `value`, other accessort mentioned accept true or false
278248

279249
<br />
280250

281-
#### Q10
282-
### Show the different options available to prevent the modifications to the object
251+
### Q. Show the different options available to prevent the modifications to the object
283252

284253
- `preventExtensions` is an Object method which prevents addition of any new property to an object
285254
- `seal` is an Object method which prevents addition and deletion of any property in an object
@@ -308,8 +277,7 @@ Object.isFrozen(obj); // true
308277

309278
<br />
310279

311-
#### Q11
312-
### Modify the given object so that it can be used inside a for...of loop
280+
### Q. Modify the given object so that it can be used inside a for...of loop
313281

314282
- Symbol iterator can be used to define the iterator on the object
315283
- The values of the object can accessed with `for..of` the way we can do it for array
@@ -354,8 +322,7 @@ const obj = {
354322

355323
<br />
356324

357-
#### Q12
358-
### Show the creation of Regular Expression in JavaScript
325+
### Q. Show the creation of Regular Expression in JavaScript
359326

360327
- Regular expressions are patterns used to match character combinations in strings
361328
- Regular expressions can be created using literal form or constructor form
@@ -380,8 +347,7 @@ In JavaScript, regular expressions are objects
380347

381348
<br />
382349

383-
#### Q13
384-
### Write a polyfill for Object.create
350+
### Q. Write a polyfill for Object.create
385351

386352
- The creating of object can happen by making constructor call to the function
387353

@@ -405,8 +371,7 @@ if (typeof Object.create !== 'function') {
405371

406372
<br />
407373

408-
#### Q14
409-
### Write a code show Optional chaining for objects and functions
374+
### Q. Write a code show Optional chaining for objects and functions
410375

411376
- The optional chaining operator (?.) permits reading the value of a property located deep within a chain of connected objects
412377
- The expression short-circuits with a return value of undefined in the absence of property
@@ -430,8 +395,7 @@ obj.func?.(args)
430395
431396
<br />
432397
433-
#### Q15
434-
### Show the usage of static variable & function in a class and accessing it from the code
398+
### Q. Show the usage of static variable & function in a class and accessing it from the code
435399
436400
- Static members of the class are class level variables and not created for each instances of the class
437401
- Static members can be accessed directly using class name
@@ -464,8 +428,7 @@ Browser.areTheySameBrowsers(browser1, browser2); // false
464428
465429
<br />
466430
467-
#### Q16
468-
### Write a class which uses private variable and function
431+
### Q. Write a class which uses private variable and function
469432
470433
- Private members of the class are only accessible within the class and instances of the class do not have access to it
471434
- Private members can be created with the prefix '#' before the name of the class member
@@ -499,8 +462,7 @@ instance.publicFunc(); // 7, 10
499462
500463
<br />
501464
502-
#### Q17
503-
### Show how inheritance works in Class and the use of super keyword with working example
465+
### Q. Show how inheritance works in Class and the use of super keyword with working example
504466
505467
- Class level inheritance can happen when a class inherits from another class using the keyword `extends`
506468
- The child class can access parent class members using the keyword `super`
@@ -553,8 +515,7 @@ component.addValues(9, -4, 6, 2); // Sum of 9,-4,6,2 is 13
553515
554516
<br />
555517
556-
#### Q18
557-
### Show the way of using Proxy for object
518+
### Q. Show the way of using Proxy for object
558519
559520
- The Proxy object enables create a proxy for another object, which can intercept and redefine fundamental operations for that object
560521
- Proxy can be set for objects (including functions and arrays) to intercept the values which gives us the control on access and modification of the real object
@@ -590,8 +551,7 @@ There are lot of other traps used in Proxy apart from `get`, `set`, `apply`
590551
591552
<br />
592553
593-
#### Q19
594-
### Show how can we use for..of loop to iterate on a range with given start and end values in an object
554+
### Q. Show how can we use for..of loop to iterate on a range with given start and end values in an object
595555
```js
596556
// Example
597557
let range = {
@@ -618,8 +578,7 @@ Object.defineProperty(range, Symbol.iterator, {
618578
619579
<br />
620580
621-
#### Q20
622-
### Prove that private looking variable in a function is not really private specific to that object
581+
### Q. Prove that private looking variable in a function is not really private specific to that object
623582
624583
- Private looking variables can be created in a function and can given access by providing function interfaces
625584
- The functions maintain a closure over function variables and hence the function variables persist inside the function interfaces

0 commit comments

Comments
 (0)