Some interview questions of JavaScript

Md Solayman
4 min readMay 8, 2021

--

  1. Truthy and Falsy Values: I have explained about in about my another article. Please visit Some Basics Of JavaScript .
  2. Null vs Undefined : In JavaScript null means value is nothing , “undefined” is a value that is assigned to a variable when it is declared in the creation or loading phase of the context execution.
  3. Double equal (==) vs triple equal (===), implicit conversion (Very Important): In JavaScript, double equal (==) only compare the values but triple equal (===) compare the values along with type. Triple equal is also called “strict equality”, “identity”. Double equal is also called “loose equality”.
  4. scope , block scope , access outer scope (Very Important): I have explained about in about my another article. Please visit Some Basics Of JavaScript .
  5. closure, encapsulation, private variable(Very Important): A closure is a function that has been packed together (enclosed) with references to its environment (the lexical environment). In other words, a closure allows an inner function to enter the domain of an outer function. Closures are generated every time a function is created in JavaScript, at function development time. In a simple word if a function is defined in another function and use the variables of its parent function then this phenomena is called closer means that inner function enclose the references of its parent function. For this reason the inner function can access the value of the variables of its parent scope.
var num1 = 2;var sum = function () {var num2 = 3;      //closure return function () {
var num3 = 4;
return function () {
return num1 + num2 + num3;
};
};
};
var myFunc = sum();
console.dir(myFunc);
//Browser Console:
ƒ anonymous()
arguments: null
caller: null
length: 0
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: test.js:4
[[Scopes]]: Scopes[2]
0: Closure (sum) {num2: 3}
1: Global {window: Window, self: Window, document: document, name: "", location: Location, …}

6. Difference between bind , call and apply (Very Important): I have explained it elaborately my another article called Some Basics Of JavaScript in the section of this keyword. Please visit Some Basics Of JavaScript .

7. window, global variable , global scope (Very Important): Please visit Some Basics Of JavaScript . I have explained there .

8. How to understand this keyword (Very Important): Please visit Some Basics Of JavaScript . The topic is explained there.

9. Asynchronous JavaScript (setTimeOut(), SetInteval()): Synchronous tasks are carried out in a sequential order, with each argument waiting for the previous one to complete before proceeding. But in case of asynchronous code, software continues to run without having to wait for asynchronous code to complete. Such setTimeOut(), SetInteval(), async function etc. During the code execution if there is any asynchronous function in the stack, JavaScript doesn’t execute that function instantly rather it assigns the task to WEB API (In case of Browser), C++ API (Node Js) and do the execution of next task in the call stack. When the WEB API completes the task, it transfers the result to an another data structure called Call Back Queue (follows the First In First Out (FIFO) data structure). If there is any promises in the WEB api then WEB api will transfer its ( promises) call back to an another queue that is called MICRO TASK QUEUE (ES6 feature) which has more priority to the event loop than the callback queue. Then when the synchronous tasks are done in the stack, by the “Event Loop” JavaScript engine takes all the results to call stack from the call back queue or micro task queue according to the preference by FIFO method and do execution.

10. How JavaScript Work, Event Loop stack , Queue: Please visit my article JavaScript Event Loop and How java script code runs? .

11. Some Problem Solving :Find the largest element of an array, Remove duplicate item from an array (Very Important), Count the number of words in a string, Reverse a string (Very Important ), Calculate Factorial of a number using for loop, Calculate Factorial in a Recursive function, Create a Fibonacci Series using a for loop (Very Important), create Fibonacci series in a recursive way (Very Important), Check whether a number is a Prime Number or not (Very Important).

12.Event bubble with example (Very Important)

13.Event delegate and purpose of Event bubble (Very Important)

14. Let, const, array declared with const, object declared with const

15. Arrow function, multiple parameter, function body

16. What is JavaScript, key features of JavaScript

17. How recursion works and recursion vs iterative

18. What is DOM (Document Object Model)

19. When and how to use JavaScript callback function

20. What is an API, the purpose of API, GET, POST

--

--

Md Solayman

An enthusiastic learner , currently focused on Web Development using HTML, CSS, Bootstrap, JavaScript , React, Node, Express Js, Mogodb.