Q6. How functions are different in JavaScript?
Q7. What are drawback of closure?
Q8. What is the type of array and How to check if object is array type or not in JavaScript?
Q9. What is the use of .join in JavaScript?
Q10. What is event loop in JavaScript?
------------------------------------------------------------------------------------------------------------------------
Q6. How functions are different in JavaScript?
Answer:
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
Q7. What are drawback of closure?
Q8. What is the type of array and How to check if object is array type or not in JavaScript?
Q9. What is the use of .join in JavaScript?
Q10. What is event loop in JavaScript?
------------------------------------------------------------------------------------------------------------------------
Q6. How functions are different in JavaScript?
Answer:
- In JavaScript, functions are first-class objects; means they are type Object.
- In JavaScript they can be “stored in variables".
- They can be passed as arguments to another functions,
- They can be created within functions, and
- They can be returned from others functions.
Q7. What are drawback of closure?
Answer:
As long as closures are active, this memory cannot be garbage collected. Therefore, closures can lead to memory leaks if not used well.
------------------------------------------------------------------------------------------------------------------------
Q8. What is the type of array and How to check if object is array type or not in JavaScript?
Answer:
Type of array is object in JavaScript.
The Array.isArray() method determines whether an object is an array.
(function(
var obj1 = ['a','b','c'];
var obj2 = new String('String');
console.log(Array.isArrary(obj1)); //true
console.log(Array.isArrary(obj2)); //false
))()
------------------------------------------------------------------------------------------------------------------------
Q9. What is the use of .join in JavaScript?
Answer:
it joins the element of array in to comma separated string.
example.
var fruits = ['apple','banana','carrot']
var strFruits = fruits.join();
console.log(strFruits); // output would be -- "apple,banana,carrot"
Q10. What is event loop in JavaScript?
Answer:
Every JavaScript call work mainly around 4 things 1) call stack, 2) Event table 3) Event queue and 4) Event loop.
- Call stack- JavaScript call stack keeps the track of current function executing and what to execute after that.
- Event table - Every time you call a setTimeout function or you do some async operation — it is added to the Event Table.
- Event Queue - When function get the result it put that in Event Queue.
- Event loop - Finally Event loop is a constantly running process that checks if call stack is empty then it look at event queue. If it found something in event queue it moves it to call stack.
https://hackernoon.com/understanding-js-the-event-loop-959beae3ac40
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------