You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/interview-questions/intermediate-level.md
+35-40Lines changed: 35 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,12 +315,12 @@ Understanding truthy and falsy values allows us to write more concise and expres
315
315
+ Public
316
316
- Can be accessed from anywhere.
317
317
+ Private
318
-
- Indicated by prefixing them with the ```#``` symbol.
318
+
- Indicated by prefixing members with the ```#``` symbol.
319
319
- Cannot be accessed from instances or child classes.
320
320
- Only available within the class itself.
321
321
- Useful for information hiding.
322
322
+ Protected
323
-
- Indicated by prefixing them with the ```_``` symbol.
323
+
- Indicated by prefixing members with the ```_``` symbol.
324
324
- Can be accessed from the within the class and any class that inherits from it.
325
325
- Useful for sharing state between classes.
326
326
@@ -365,6 +365,8 @@ Example of encapsulation using getters and setters:
365
365
// ...validate new ID
366
366
this.#id = id;
367
367
}
368
+
369
+
// ...
368
370
}
369
371
```
370
372
@@ -393,54 +395,47 @@ Example of encapsulation using getters and setters:
393
395
394
396
classPersonextendsAnimal {
395
397
constructor(name) {
396
-
// Call the parent class constructor
397
-
super("Human");
398
+
super("Human"); // Call the parent class constructor
398
399
this.name= name;
399
400
}
400
401
}
401
402
```
402
-
- If no constructor is explicitly declared, a default one will be given to the class.
403
-
404
-
- Base class - If the class doesn't extend any other class, a default constructor will be assigned to it:
405
-
406
-
```javascript
407
-
constructor() {}
408
-
```
409
-
410
-
- Child class- If the classextendsanotherclass, it will inherit its constructor
411
-
412
-
```javascript
413
-
class Vehicle {
414
-
constructor(type) {
415
-
this.type= type;
416
-
}
417
-
418
-
move() {
419
-
return`The ${this.type} is moving`;
420
-
}
403
+
+iv. Defaultconstructor - If no constructor is explicitly declared, a default one will be given to the class.
404
+
- Base class - If the class doesn't extend any other class, a default constructor will be assigned to it:
405
+
```javascript
406
+
constructor() {}
407
+
```
408
+
- Child class- If the classextendsanotherclass, it will inherit its constructor
409
+
```javascript
410
+
class Vehicle {
411
+
constructor(type) {
412
+
this.type= type;
421
413
}
422
414
423
-
classCarextendsVehicle {
424
-
#model;
425
-
426
-
setmodel(model) {
427
-
this.#model = model;
428
-
}
429
-
430
-
drive() {
431
-
`Driving ${this.#model}`;
432
-
}
415
+
move() {
416
+
return`The ${this.type} is moving`;
433
417
}
434
-
```
418
+
}
435
419
436
-
Even though the constructor is not explicitly declared, the class Car inherits it from the Vehicle class:
420
+
classCarextendsVehicle {
421
+
#model;
437
422
438
-
```javascript
439
-
constructor(type) {
440
-
super(type);
423
+
setmodel(model) {
424
+
this.#model = model;
425
+
}
426
+
427
+
drive() {
428
+
`Driving ${this.#model}`;
441
429
}
442
-
```
430
+
}
431
+
```
432
+
Even though the constructor is not explicitly declared, the class Car inherits it from the Vehicle class:
433
+
```javascript
434
+
constructor(type) {
435
+
super(type);
436
+
}
437
+
```
443
438
444
439
### 8.6. Static members vs Instance members
445
440
446
-
**Answer:** By default, properties and methods that we define inside a class, belong to each instance of the classthat we create. We can also assign members to the classitself. Such members are called static, and are declared using the ```static```keyword. They cannot be directly accessed on instances of the class.
441
+
**Answer:** By default, properties and methods which we define inside a classbelong to each instance of the classthat we create. We can also assign members to the classitself. Such members are called static and are declared using the ```static```keyword. They cannot be directly accessed on instances of the class.
0 commit comments