Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 26, 2021 10:55 am GMT

5 Interview QuestionsEvery JavaScript Developer Should Know

These are some of the general Interview Questions Every JavaScript Developer Should Know

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

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.

Good to hear:

Prototypal inheritance (also: prototypes, OLOO).
Functional programming (also: closures, first class functions, lambdas).

Red flags:

No clue what a paradigm is, no mention of prototypal oo or functional programming.

2. What is functional programming?

Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data. Lisp (specified in 1958) was among the first languages to support functional programming, and was heavily inspired by lambda calculus. Lisp and many Lisp family languages are still in common use today.
Functional programming is an essential concept in JavaScript (one of the two pillars of JavaScript). Several common functional utilities were added to JavaScript in ES5.

Good to hear:

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.

Red flags:

No mention of pure functions / avoiding side-effects.
Unable to provide examples of functional programming languages.
Unable to identify the features of JavaScript that enable FP.

3. What is the difference between classical inheritance and prototypal inheritance?

Class Inheritance: instances inherit from classes (like a blueprint a description of the class), 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.
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.

In JavaScript, prototypal inheritance is simpler &

more flexible than class inheritance.

Good to hear:

Classes: create tight coupling or hierarchies/taxonomies.
Prototypes: mentions of concatenative inheritance, prototype delegation, functional inheritance, object composition.

Red Flags:

No preference for prototypal inheritance & composition over class inheritance.

4. What are the pros and cons of functional programming vs object-oriented programming?

OOP Pros: Its 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.

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.

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

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.

More people are familiar with OO and imperative programming than functional programming, so even common idioms in functional programming can be confusing to new team members.
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.

Good to hear:

Mentions of trouble with shared state, different things competing for the same resources, etc
Awareness of FPs capability to radically simplify many applications.
Awareness of the differences in learning curves.
Articulation of side-effects and how they impact program maintainability.
Awareness that a highly functional codebase can have a steep learning curve.
Awareness that a highly OOP codebase can be extremely resistant to change and very brittle compared to an equivalent FP codebase.
Awareness that immutability gives rise to an extremely accessible and malleable program state history, allowing for the easy addition of features like infinite undo/redo, rewind/replay, time-travel debugging, and so on. Immutability can be achieved in either paradigm, but a proliferation of shared stateful objects complicates the implementation in OOP.

Red flags:

Unable to list disadvantages of one style or another Anybody experienced with either style should have bumped up against some of the limitations.

5. When is classical inheritance an appropriate choice?

The answer is never, or almost never. Certainly never more than one level. Multi-level class hierarchies are an anti-pattern. Ive been issuing this challenge for years, and the only answers Ive ever heard fall into one of several common misconceptions. More frequently, the challenge is met with silence.

Good to hear:

Rarely, almost never, or never.
A single level is sometimes OK, from a framework base-class such as React.Component.
Favor object composition over class inheritance.

JOIN THEVIKCODE NEWLETTER ( GET DAILY WHICH WILL NOT BE AVAIBLE HERE ) - https://thevikcode.substack.com/


Original Link: https://dev.to/circle/5-interview-questions-every-javascript-developer-should-know-520a

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To