Some common interview questions about Advanced Js

Md. Riduanul Haque
2 min readNov 6, 2020
  • Truthy -falsy: truthy value and false value. javaScript has some value which is by default defined as falsy.
  • falsy value — * ‘ ’ empty string, 0 zero, null, undefined, Nan.
  • truthy value — others are truthy value.

Example:

console.log(" ") // false
console.log("riduanul") // true
console.log(0) // false
console.log(123) // true
console.log(-123) // ture, minus value also true.
console.log(null) // false
console.log(Nan) // false
  • React Hooks: without using react class we can use state and other things that new feature comes from react that's called React hooks. now we no need a class-based component.
  • Rules of Hooks: 1. only call hooks at the top level, we can’t use call hooks inside a function, inside a loop, inside a condition. 2. only call hooks from react function, we can’t call hooks from a regular javascript function.
  • React Hooks:
  • useState
  • useEffect
  • useContext
  • useReducer
  • useCallback
  • useMemo
  • useRef
  • useImperativeHandle
  • useLayoutEffect
  • useDebugValue
  • useState hook: if you want to change a state value in your UI then you can use this useState Hook. see the example below.

Example:

//useState
function useState() {
const [count, setCount] = useState(0);return(<h1> increase and decrease ure number {count} </h1>
<button onClick={() => setCount(count + 1)}> increase</button>
<button onClick={() => setCount(count -1)}> decrease</button>
/// count will increase by increase button
/// count will decrease by decrease button
  • Double equal vs triple equal:

Triple equal compare strictly value and data type but double equal compare only value. see the example below

Example

var number = 20;
var string = '20';
if (number == string) {
console.log(true)
}
ans: true; /// both value are same but data type not same.
if (number === string){
console.log(true)
}
ans: false; /// number and string are not in same data type.
  • map: map returns an array from the array of the same length.

Example:

var friends = [
{name:munna, id:01}, {name:riduanul, id:02},{name:haque, id:03}
];
var names = friends.map(friend => friend.name);
console.log(names);
//res[munna,riduanul,haque];
  • filter: filter returns an array from the array of fewer items than the original array that you conditioned to display.

Example:

{name:munna, id:01}, {name:riduanul, id:02},{name:haque, id:03}
];
var friend = friends.filter(friend => friend.id > 01);
console.log(friend);
//res[{name:riduanul, id:02},{name:haque, id:03}];
  • find: find returns the first items from the array you conditioned to display.

Example:

{name:munna, id:01}, {name:riduanul, id:02},{name:haque, id:03}
];
var friend = friends.find(friend => friend.id > 01);
console.log(friend);
//res[{name:riduanul, id:02}];
  • closer: if you call or return a function from a function then that function creates a close scope. and inner function can access a variable out of the function. then the function store a personal value. that’s called closer.

Example:

function stopWatch(){  
var count = 0;
return fucntion watch(){
count++
return count;
}
}
const watch1 = stopWatch();
const watch2 = stopWatch();
console.log(watch1());
console.log(watch1());
console.log(watch1());
console.log(watch2());
console.log(watch2());
console.log(watch1());
///res 1,2,3,1,2,4

--

--