Front-end Flashcards

Interview questions

1
Q

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

A

JavaScript is a multi-paradigm language, supporting imperative/procedural programming along with OOP (Object-Oriented Programming) and functional programming. JavaScript supports OOP 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 is an essential concept in JavaScript (one of the two pillars of JavaScript). Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data.

  • Pure functions / function purity.
  • Avoid side-effects.
  • Simple function composition.
  • Examples of functional languages: Lisp, ML, Haskell, Erlang, Clojure, Elm, F Sharp, OCaml, etc…
  • Mention of features that support FP: first-class functions, higher order functions, functions as arguments/values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between classical inheritance and prototypal inheritance?

A

Class Inheritance: instances inherit from classes, and create sub-class relationships: hierarchical class taxonomies. Instances are typically instantiated via constructor functions with the new keyword. Class inheritance may or may not use the class keyword from ES6.

In JavaScript, prototypal inheritance is simpler &
more flexible than class inheritance.

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

What are the pros of functional programming ?

A

FP Pros: Using the functional paradigm, programmers avoid any shared state or side-effects, which eliminates bugs caused by multiple functions competing for the same resources. With features such as the availability of point-free style (aka tacit programming), functions tend to be radically simplified and easily recomposed for more generally reusable code compared to OOP.

FP also tends to favor declarative and denotational styles, which do not spell out step-by-step instructions for operations, but instead concentrate on what to do, letting the underlying functions take care of the how. This leaves tremendous latitude for refactoring and performance optimization, even allowing you to replace entire algorithms with more efficient ones with very little code change. (e.g., memoize, or use lazy evaluation in place of eager evaluation.)

Computation that makes use of pure functions is also easy to scale across multiple processors, or across distributed computing clusters without fear of threading resource conflicts, race conditions, etc…

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

What are the cons of functional programming ?

A

FP Cons: Over exploitation of FP features such as point-free style and large compositions can potentially reduce readability because the resulting code is often more abstractly specified, more terse, and less concrete.

FP has a much steeper learning curve than OOP because the broad popularity of OOP has allowed the language and learning materials of OOP to become more conversational, whereas the language of FP tends to be much more academic and formal. FP concepts are frequently written about using idioms and notations from lambda calculus, algebras, and category theory, all of which requires a prior knowledge foundation in those domains to be understood.

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

What are the pros of object-oriented programming?

A

OOP Pros: It’s easy to understand the basic concept of objects and easy to interpret the meaning of method calls. OOP tends to use an imperative style rather than a declarative style, which reads like a straight-forward set of instructions for the computer to follow.

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

What are the cons of object-oriented programming?

A

OOP Cons: 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 with non-deterministic order, which may lead to undesirable behavior such as race conditions.

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

The answer is never, or almost never. Certainly never more than one level. Multi-level class hierarchies are an anti-pattern.

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

There is more than one type of prototypal inheritance:

Delegation (i.e., the prototype chain).
Concatenative (i.e. mixins, `Object.assign()`).
Functional (Not to be confused with functional programming. A function used to create a closure for private state/encapsulation).
Each type of prototypal inheritance has its own set of use-cases, but all of them are equally useful in their ability to enable composition, which creates has-a or uses-a or can-do relationships as opposed to the is-a relationship created with class inheritance.
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

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

In other words, use can-do, has-a, or uses-a relationships instead of is-a relationships.

  • Avoid class hierarchies.
  • Avoid brittle base class problem.
  • Avoid tight coupling.
  • Avoid rigid taxonomy (forced is-a relationships that are eventually wrong for new use cases).
  • Avoid the gorilla banana problem (“what you wanted was a banana, what you got was a gorilla holding the banana, and the entire jungle”).
  • Make code more flexible.
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 means that UI fields are bound to model data dynamically such that when a UI field changes, the model data changes with it and vice-versa.

One way data flow means that the model is the single source of truth. Changes in the UI trigger messages that signal user intent to the model (or “store” in React). Only the model has the access to change the app’s state. The effect is that data always flows in a single direction, which makes it easier to understand.

One way data flows are deterministic, whereas two-way binding can cause side-effects which are harder to follow and understand.

  • React is the new canonical example of one-way data flow. Cycle.js is another popular implementation of uni-directional data flow.
  • Angular is a popular framework which uses two-way binding.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the pros and cons of monolithic vs microservice architectures?

A

A monolithic architecture means that your app is written as one cohesive unit of code whose components are designed to work together, sharing the same memory space and resources.

A microservice architecture means that your app is made up of lots of smaller, independent applications capable of running in their own memory space and scaling independently from each other across potentially many separate machines.

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

What is asynchronous programming, and why is it important in JavaScript?

A

Asynchronous programming means that the engine runs in an event loop. When a blocking operation is needed, the request is started, and the code keeps running without blocking for the result. When the response is ready, an interrupt is fired, which causes an event handler to be run, where the control flow continues. In this way, a single program thread can handle many concurrent operations.

User interfaces are asynchronous by nature, and spend most of their time waiting for user input to interrupt the event loop and trigger event handlers.

Node is asynchronous by default, meaning that the server works in much the same way, waiting in a loop for a network request, and accepting more incoming requests while the first one is being handled.

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

What is synchronous programming in JS?

A

Synchronous programming means that, barring conditionals and function calls, code is executed sequentially from top-to-bottom, blocking on long-running tasks such as network requests and disk I/O.

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

What are the differences between null and undefined?

A

JavaScript has two distinct values for nothing, null and undefined.

  • undefined means, value of the variable is not defined. undefined is a type with exactly one value: undefined
  • null means empty or non-existent value which is used by programmers to indicate “no value”. null is a primitive value and you can assign null to any variable. null is not an object, it is a primitive value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the differences between == and ===?

A

== will not check types and === will check whether both sides are of same type.

17
Q

How would you compare two objects in JavaScript?

A

Equality check will check whether two objects have same value for same property. To check that, you can get the keys for both the objects. If the number of properties doesn’t match, these two objects are not equal. Secondly, you will check each property whether they have the same value. If all the properties have same value, they are equal.

18
Q

ABOUT W3C

A

The World Wide Web Consortium (W3C) is an international community where Member organizations, a full-time staff, and the public work together to develop Web standards.
W3C standards define an Open Web Platform for application development that has the unprecedented potential to enable developers to build rich interactive experiences, powered by vast data stores, that are available on any device.

19
Q

Describe the difference between tags “script”, “script async” and “script defer”

A

script- HTML parsing is blocked, the script is fetched and executed immediately, HTML parsing resumes after the script is executed.
script async - The script will be fetched in parallel to HTML parsing and executed as soon as it is available (potentially before HTML parsing completes).
script defer - The script will be fetched in parallel to HTML parsing and executed when the page has finished parsing. If there are multiple of them, each deferred script is executed in the order they were encoun­tered in the document. If a script relies on a fully-parsed DOM, the defer attribute will be useful in ensuring that the HTML is fully parsed before executing.