Going through a company hiring process is hard. Many stages of interviews, questions and meetings have to be made before the two parts can make a common decision. However, in all of these stages, we can identify one that is extremely important. This will decide whether or not you will be hired, and that is the technical interview.
#1 What is the difference between var and let?
“The difference between var and let is that var is function scoped while let is block-scoped”
This paradigm is already extremely common in other languages, let’s see a quick example of how it works practically.
As you can see from the above example, since let is block-scoped, defining action inside our curly braces doesn’t interfere at all with the action variable outside of the block.
#2 Explain the difference between == and ===
The difference between these operators is that:
The ”==” operator performs a test based on abstract equality ( the necessary type conversions before doing the equality comparison is applied).
While the “===” operator tests for strict equality (no type conversion is applied, meaning that if two values are not of the same type when compared, the operator will return false).
In particular, you have to remember
- Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
- Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
- Two Boolean operands are strictly equal if both are true or both are false.
- Two objects are strictly equal if they refer to the same Object.
- Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]
The “strict mode” is a feature that was born with ECMAScript 5, it allows you to put your application into an operating context that is “strict”. Practically this means that certain operations that are considered to be unsafe will be rejected and errors will be thrown. Benefits of using this mode include:
- Prevents unsafe actions to be performed
- Makes writing safer code easier
- Prohibits some syntax likely that is probably going to be implemented as a part of future versions of the language.
#4 What is a callback?
“A callback is a function that will be executed after another function has finished executing “. Callback functions are great whenever you have to perform some operations after another one has been completed. For example, if you want to print some data after an API request has been completed.
#5 What is a closure?
A closure is simply an inner function that has access to the variables in the enclosing outer function’s scope. So a closure will have access to three particular scopes:
- The variables in its own scope
- The global variables
- The variable in the enclosing function’s scope
#6 What is a pure function?
To be considered pure, a function has to pass the following tests:
- It always returns the same result if the same arguments are passed in. And It does not depend on any state, or data, change during a program’s execution. It must only depend on its input arguments.
- It doesn’t produce any observable side effects (network requests, data mutation).
Using pure functions come with many benefits including:
- Easier and immediate testing: since they will always produce the same results if you pass in the same arguments.
- Easier maintenance: change a pure function and just don’t worry about any possible side effects caused by changing variables values.
#7 What is a promise
A Promise is an object representing the eventual completion or failure of an asynchronous operation. In substance, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function. So with them, instead of writing old school callback functions like this:
you would write something like:
#8 What is functional programming
Functional programming is a development paradigm, which means that it’s a way of thinking and structuring our code based on certain rules and fundamentals. It is a declarative paradigm rather than an imperative one, where the state of our application flows through our pure functions instead of being shared with methods belonging to objects. The basics structures of this paradigm are:
- Pure functions
- Function composition
- Avoiding shared state
- Avoiding mutating state
- Avoiding causing side effects
#9 What is function composition
#10 Describe what is the difference between classical inheritance and prototypal inheritance?
Class Inheritance: instances inherit from classes (which provides a scaffolding for its instances), and create sub-class relationships. Instances are typically instantiated via constructor functions with the new keyword.
Prototypal Inheritance: in this case instances inherit directly from other objects. They are typically instantiated via factory methods or Object.create().
I hope this article was helpful as a quick refresher for you in order to be better prepared for your next interview and, possibly, land that dream job. Continue to follow CodeWall for more articles like this!