Weak Areas Flashcards

(33 cards)

1
Q

What is a closure in JavaScript?

A

A closure is when a function remembers and can access variables from its outer scope even after that outer function has finished executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is memoization used for?

A

Memoization is used to speed up functions by caching the results of expensive function calls and returning the cached result when the same input occurs again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does memoization typically use closures?

A

Memoization uses closures to maintain a private cache object that persists across calls to the memoized function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Object-Oriented Programming (OOP) in JavaScript?

A

A programming paradigm based on objects and classes to model real-world things using properties and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the four main principles of OOP?

A

Encapsulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is encapsulation?

A

Hiding the internal details of an object and exposing only what is necessary through public methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is abstraction?

A

Hiding complex implementation details and showing only the necessary features of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is inheritance in JavaScript?

A

A mechanism where one object can acquire properties and methods from another object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is polymorphism?

A

The ability of different objects to be accessed through the same interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create an object in JavaScript?

A

Using object literals {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a class in JavaScript?

A

A blueprint for creating objects with shared properties and methods introduced in ES6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you define a class in JavaScript?

A

Using the ‘class’ keyword, followed by the class name and a constructor method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a constructor method?

A

A special method used for initializing new objects created from a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you create an instance of a class?

A

Using the ‘new’ keyword followed by the class name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the ‘this’ keyword in JavaScript?

A

Refers to the current object instance within a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is method overriding?

A

Providing a new implementation of a method inherited from a parent class.

17
Q

What is a prototype in JavaScript?

A

An object from which other objects inherit properties and methods.

18
Q

What is the prototype chain?

A

A mechanism where objects inherit from other objects

19
Q

How does JavaScript handle inheritance?

A

Through prototypes and the prototype chain.

20
Q

What is the difference between class-based and prototype-based OOP?

A

Class-based uses classes and instances; prototype-based uses objects and their prototypes directly.

21
Q

Can you modify a prototype?

22
Q

What is the benefit of using prototypes?

A

It allows sharing methods across all instances

23
Q

How can you achieve encapsulation in JavaScript?

A

Using closures or the new private fields (#) syntax inside classes.

24
Q

What are private fields in JavaScript classes?

A

Properties prefixed with # that cannot be accessed outside the class.

25
What is static method in JavaScript?
A method defined on the class itself
26
How do you define a static method?
Using the 'static' keyword inside the class.
27
What is the difference between 'instance method' and 'static method'?
Instance methods are called on objects; static methods are called on the class itself.
28
What is super() in JavaScript?
A method to call the parent class constructor from a child class constructor.
29
What is the difference between 'object' and 'class' in JavaScript?
An object is an instance; a class is a blueprint to create instances.
30
What is duck typing in JavaScript?
A concept where an object's suitability is determined by the presence of certain methods and properties rather than the object's type.
31
What is composition vs inheritance?
Composition combines simple objects to build complex ones; inheritance derives new objects from existing ones.
32
When should you prefer composition over inheritance?
When you want more flexibility and to avoid deep inheritance hierarchies.
33