Interview questions JavaScript Flashcards

1
Q

Can you name two programming paradigms important for JavaScript app developers?

A
  • JavaScript supports imperative/procedural programming along with Object-Oriented Programming and functional Programming.

JavaScript supports Object-Oriented Programming with prototypal inheritance.

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

What is functional programming?

A

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data.

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

What is the difference between classical and prototypal inheritance?

A

Classical Inheritance: instances inherit from classes and create sub-class relationships. Instances are typically instantiated via constructor functions with the new keyword. It may or may not use the class keyword. (Syntactic sugar)

Prototypal Inheritance:
Instances inherit directly from other objects. Instances are typically instantiated via factory functions or Object.create(). Instances may be composed from many different objects, allowing for easy selective inheritance.

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

What are the pros of Object-oriented programming?

A

It’s easy to understand the basic concept of objects and easy to interpret the meaning of method calls. Tends to use an imperative style rather than a declarative style.

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

What are the cons of Object-Oriented programming?

A

OOP typically depends on shared state. Objects and behaviors are typically tacked together on the same entity, which may be accessed at random by any number of functions in a non-deterministic order. May lead to undesirable behavior like race conditions.

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

What are pros of functional programming?

A
  • Avoid any shared state or side-effects. Eliminates bugs caused by multiple functions competing for same resources.
  • Functions tend to be radically simplified, easily recomposed.
  • Tends to favor declarative and denotational styles.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are cons of functional programming?

A

Over-exploitation can reduce readability.

More people are familiar with OO and imperative programming.

FP has a much steeper learning curve.

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

When is classical inheritance an appropriate choice?

A

Never more than one level.

Favor object composition over class inheritance.

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

when is prototypal inheritance an appropriate choice?

A

(More than one type)

  • Delegation
  • Concatenative
  • Functional

All are equally useful in creating composition.

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

What does ‘Favor object composition over class inheritance’ mean?

A

Code reuse should be achieved by assembling smaller units of functionality into new objects instead of inheriting from classes and creating object taxonomies.

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

What are two-way data binding and one-way data flow, and how are they different?

A

Two-way data binding: UI fields are bound to model data dynamically such that when a UI field changes, the model data changes with it.

One-way data flow: The model is the single source of truth. Changes in the UI trigger messages that signal user intent to the model.

Only the model has the access to change the app’s state.

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

What is a monolithic architecture?

A

Means your app is written as one cohesive unit of code whose components are designed to work together.

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

What is a microservice architecture?

A

Your app is made up of lots of smaller, independent applications capable of running in their own memory space and scale independently.

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

What are the pros of a monolithic architecture?

A

Many apps have cross-cutting concerns. When everything is running through the same app, it’s easy to hook up components to those cross-cutting concerns.

  • There can also be performance advantages. shared-memory access is faster than inter-process communication.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are cons of a monolithic architecture?

A

They tend to get tightly coupled and entangled as the app evolves. It is difficult to isolate services for purposes such as independent scaling or code maintainability.

  • difficult to understand.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are pros of a microservice architecture?

A
  • Generally better organized since each microservice does a specific job. Can have performance advantages depending on how they’re organized.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are cons of a microservice architecture?

A

Unanticipated cross-cutting concerns.

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

What is async, and why is it important?

A

Synchronous: Code executed from top to bottom.

Async: engine runs in an event loop.

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

How does asynchronous programing work?

A

The entire engine runs in an event loop, and when a blocking operation is needed, the request is started, and the code keeps running without blocking for the result.

When response is ready, interrupt is fired, causing event handler to be run.

20
Q

What do bind(), apply(), and call() do?

A

They set this to a provided value, and also take in arguments.

21
Q

What are the differences between bind apply and call?

A

bind allows you to call a function later with a certain context.

Call and apply invoke the function immediately. Call accepts an argument list while apply accepts a single array of arguments.

22
Q

What is the use of Bind?

A

It allows us to inject a context into a function which returns a new function with updated context. this becomes a user-supplied variable, which is great for events.

23
Q

What are the three types of JavaScript scopes?

A
  • Global Scope,
  • Local/Function Scope
  • Block Scope
24
Q

What is global scope?

A

What we normally do, when we declare variable globally.

25
Q

What is local/function scope?

A

When you declare a variable inside of a function.

26
Q

What is block scope?

A

When the variable’s scope is limited to a given block.

27
Q

What are the rules of the this keyword?

A

Global context - Refers to window object.

Local context - Refers to enclosing object. ‘Whenever a function is called by a preceding dot, that thing before the dot is this’

Whenever a constructor function is used, this refers to the specific instance of the object that is created and returned by the constructor function.

Whenever call or apply is used, this is explicitly defined.

28
Q

What are the ways of creating an object?

A
var obj = {};
var obj = new Object();
29
Q

How do you convert an object into a JSON string? How do you turn it back?

A

You convert a given object into a JSON string using JSON.stringify.

You turn it back with JSON.parse.

30
Q

How do you iterate over an object?

A

Either use a for in loop, or use object.keys

31
Q

What does object.values do?

A

Returns a list of values of an object.

32
Q

What does object.prototype do?

A

Provides a list of an object’s prototype, and all of the functions that exist on it.

33
Q

What does Object.prototype.hasOwnProperty do?

A

Helps to find out whether a given property/key exists in an object.

34
Q

What does Object.prototype.instanceof do?

A

-Evaluates whether a given object is the type of a particular prototype.

35
Q

What does Object.freeze do?

A

Allows us to freeze an object so that existing properties cannot be modified.

36
Q

What does Object.seal do?

A

It allows configurable properties but won’t allow new property addition or deletion of properties.

37
Q

What is prototypical inheritance?

A

Essentially setting properties on the object prototype, allowing you to create new objects that have those same properties.

38
Q

What are callbacks?

A

Callbacks are functions executed after an I/O operation is done.

39
Q

What are promises?

A

They are wrappers for callbacks which allow us to asynchronously code elegantly. Can control the flow of asynchronous operations.

40
Q

What are the two ways of creating regular expressions?

A
var reg = /ar/;
var reg = new RegExp('ar');
41
Q

What does map in javascript do?

A

We can get a new array by applying a transformation function on every element of that array.

42
Q

What does reduce do?

A

Reduces a given list to one final result. Cleaner than iterating.

43
Q

What does filter do?

A

processes each element in an array, and returns all of the ones that pass a test.

44
Q

How can we handle errors?

A

Use try… catch blocks, or if using promises have a rejection block.

45
Q

What is hoisting?

A

The process of pushing undeclared variables to the top of the program while running it.

46
Q

What is event bubbling?

A

A way of event propagation in the HTML DOM API when an event occurs in an element inside another element. Propagate upwards.

47
Q

What is event capturing?

A

The opposite of bubbling. Events propagate inwards instead of outwards.