Interview questions JavaScript Flashcards
Can you name two programming paradigms important for JavaScript app developers?
- JavaScript supports imperative/procedural programming along with Object-Oriented Programming and functional Programming.
JavaScript supports Object-Oriented Programming with prototypal inheritance.
What is functional programming?
Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data.
What is the difference between classical and prototypal inheritance?
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.
What are the pros of Object-oriented programming?
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.
What are the cons of Object-Oriented programming?
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.
What are pros of functional programming?
- 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.
What are cons of functional programming?
Over-exploitation can reduce readability.
More people are familiar with OO and imperative programming.
FP has a much steeper learning curve.
When is classical inheritance an appropriate choice?
Never more than one level.
Favor object composition over class inheritance.
when is prototypal inheritance an appropriate choice?
(More than one type)
- Delegation
- Concatenative
- Functional
All are equally useful in creating composition.
What does ‘Favor object composition over class inheritance’ mean?
Code reuse should be achieved by assembling smaller units of functionality into new objects instead of inheriting from classes and creating object taxonomies.
What are two-way data binding and one-way data flow, and how are they different?
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.
What is a monolithic architecture?
Means your app is written as one cohesive unit of code whose components are designed to work together.
What is a microservice architecture?
Your app is made up of lots of smaller, independent applications capable of running in their own memory space and scale independently.
What are the pros of a monolithic architecture?
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.
What are cons of a monolithic architecture?
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.
What are pros of a microservice architecture?
- Generally better organized since each microservice does a specific job. Can have performance advantages depending on how they’re organized.
What are cons of a microservice architecture?
Unanticipated cross-cutting concerns.
What is async, and why is it important?
Synchronous: Code executed from top to bottom.
Async: engine runs in an event loop.