W.I.P Javascript Interview Preparation

V24.08.03

1. What is the difference between let, const and var?

Ans:- In javascript these are used in declaring variables .

  1. Var are function-scoped, meaning they are only accessible within the function they are declared in. If they are not declared inside any function, they are globally scope.
  2. let and const are block scope

in const, we can’t reassign the values for the same variable.

2. What is Hoisting ?

Ans:-

  1. This is a behavior, which is happening in the compile phase. (memory allocation) Phase
  2. Where the variable and function declarations are moved to the top of their containing scope.
  3. it’s important to note that only the declarations are hoisted, not initialization.

NOTE:-
let and const are hoist there variable but they are in a different Place. they are in an uninitialized zone. i.e called *Temporal Dead Zone *

3. What is Closure?

Ans:-

  1. A function created inside another function has access to variables declared in its parent function, even after the parent function has finished execution.
  2. This concept is called Closure.
  3. This approach is used in Modular patterns in javascript (Functional Programming)

4. What is ersistance Lexical Scope Reference Data? (P.L.S.R.D) Lexical/static (BackPack) ?

Ans:-

  1. As mentioned above the closure have the access of outer scope Variables, as because of this .
  2. Actually it takes the variables along with the return function.as like backpack

5. What is Higher Order function

Ans:-

  1. A function which takes or return a function is called higher order function,

Ex:- map, filter , reduce of Array, + closure

6. What is Currying?

Ans:-

  1. Currying is a technique in JavaScript where a function with multiple arguments is transformed into a sequence of functions, each with a single argument. Each function returns another function that takes the next argument until all arguments are used.
function curryAdd(a) { return function(b) { return function(c) { return a + b + c; } }
} const add = curryAdd(1)(2)(3); // Outputs: 6
Enter fullscreen mode Exit fullscreen mode

Advantages:-

  1. Function Composition: Curried functions are extremely useful in function composition. Since each function takes just one argument, it’s easy to create a pipeline of functions where the output of one function is the input of the next.

  2. Lazy Evaluation: Currying can be used to produce new functions for delayed computation. The evaluation of the function gets delayed until all the necessary arguments are available.

7. What is Scope and Lexical Scopeing?

Ans:-

  1. In JavaScript, scope refers to the context in which variables are declared, initialized, and accessed. There are three types of scope:

a. Global Scope: Variables declared outside of any function or block are in the global scope and can be accessed from anywhere in the code.

b. Function Scope: Variables declared within a function using the var keyword are in the function scope and can only be accessed within that function.

c. Block Scope: Variables declared within a block (for example, within an if statement or for loop) using the let or const keyword are in the block scope and can only be accessed within that block.

  1. Lexical scoping, also known as static scoping, is a convention used by JavaScript to determine the accessibility of variables, functions, and objects based on their physical location in the source code. In lexical scoping, a child scope always has access to the variables declared in its parent scope.

8. What is this?

Ans:-

  1. In JavaScript, this is a special keyword that refers to the context in which a function is called.
  2. The value of this depends on how the function is called, not where the function is declared.

  3. In a regular function declaration, this is dynamically bound. This means that its value is determined by how the function is called.
    Here’s an example:

function myFunction() { console.log(this);
} const myObject = { name: 'My Object' }; // Call myFunction as a method of myObject
myObject.myMethod = myFunction;
myObject.myMethod(); // Outputs: { name: 'My Object', myMethod: [Function: myFunction] }
Enter fullscreen mode Exit fullscreen mode
  1. However, in an arrow function, this is lexically bound. This means that its value is determined by the surrounding scope at the time the function is declared, not by how the function is called.

Here’s an example:

const myObject = { myMethod: () => { console.log(this); }
}; myObject.myMethod(); // Outputs: window (browser)
Enter fullscreen mode Exit fullscreen mode

Depending on your need you can use the this

Call, apply and bind

  1. In JavaScript, call, apply, and bind are methods used to control the context of this in a function.
//Call
function greet() { console.log(`Hello, ${this.name}`);
} const user = { name: 'John' };
greet.call(user); // Outputs: "Hello, John" //apply function greet(greeting, punctuation) { console.log(`${greeting}, ${this.name}${punctuation}`);
} const user = { name: 'John' };
greet.apply(user, ['Hello', '!']); // Outputs: "Hello, John!" //bind will return a function function greet() { console.log(`Hello, ${this.name}`);
} const user = { name: 'John' };
const greetUser = greet.bind(user); greetUser(); // Outputs: "Hello, John" 
Enter fullscreen mode Exit fullscreen mode

9. What is prototype and prototype chain ?
10. What is Prototype inheritance ?
11. What is Class and Inheritance ?
12. When we create instance how much Memory it captures ?
13. What is Event Loop ?
14. What is Macro task queue and Micro task queue ?
15. What is Event Delegation ?
16. What is Pure function ?
17. Map, Set, week map and Week Set , What are these and What are the Benefit of it ?
18. DisAdvantages of Closure ?
19. How Javascript is doing the garbage Collection, What algorithm it is using?
20. How == and === are similar ?
21. Which tasks are the JS Engine put in micro task Queue ?
22. What is difference between Object.create() and Object.assign() ?
23. What is Difference between proto && Prototype ?

Ans:-

  1. proto: This is a property of an object, pointing to the prototype of the constructor function that created the object.
 //For example, let obj = new SomeConstructor();
obj.__proto__ will point to SomeConstructor.prototype. 
Enter fullscreen mode Exit fullscreen mode
  1. This property is used to climb up the prototype chain when accessing properties or methods, allowing objects to inherit features from their prototypes.

24. Functions is Javascript ?
Ans:- First class Objcets
functions = function + Object combo
function declaration vs function expression
named function expression anonymous function expression
Arrow function, normal function
how this change in both function types
parameter , argument

25. What is the use of new keyword ?
26. javascript Primary patterns


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Chan ho park 박찬호 chan ho park 박찬호는 mlb 역사상 처음으로 대한민국 출신 선수이자 mlb 올스타에 선정된 첫 번째 대한민국 선수입니다.