Notes from Interviews
esther
Some notes from those technical interviews I had so far
Talked with some mentors on ADPList 🥰
Pure function
function pure (num) {
return num * 5;
}
- Always returns same result
- Never depends on any state/data/change
- Always return something
- Test cases will be straighforward
High Order Function
- Takes another function as an argument
- Returns function
High Order Component
- Takes a component as an input and returns a new compnent
- Idealy enhance the component
- Usually a pure function and returns a new component
- Use cases: loader while fetching data
Undefined VS null
Undefined | Null |
---|---|
Declared, but not yet defined | No value, on purpose |
The type is undefined | The type is object |
Equal to NaN | Equal to 0 |
THIS
In a method
refer to the owner object (me)
var me = {
firstName: 'John',
lastName: 'Doe',
fullName: function () {
return this.firstName + ' ' + this.lastName;
}
}
Alone & Independent
refer to the global object (window)
var x = this.name;
In a function
refer to the global object
function myFunction () {
return this.name;
}
In a function “strict mode”
undefined
"use strict"
function myFunction () {
return this.name;
}
In Event Handlers
refer to the HTML Element that received the event (button)
<button onclick="this.style.display='none'">
Button
</button>
call()
& apply()
- Explict binding
force the function(a) to refer to the object(b)
var a = {
fullName: function () {
return this.firstName + ' ' + this.lastName;
}
}
var b = {
firstName: 'John',
lastName: 'Doe',
}
a.fullName.call(b);