javascript_Node_Express Questions
javascript_Node_Express Questions
Answer: undefined is a variable that has been declared but not assigned a value,
while null is an intentional absence of any object value.
Answer: A closure is a function that has access to variables from its outer
(enclosing) scope even after the outer function has finished executing. Example:
Function outer() {
Let outerVar = 10;
Function inner() {
Console.log(outerVar);
}
Return inner;
}
Const closureExample = outer();
closureExample(); // Outputs: 10
8. Hard: Explain the concept of the event loop in Node.js and how it facilitates
non-blocking I/O.
Answer: The event loop is a core concept in Node.js that continuously checks the
message queue for events. It enables asynchronous, non-blocking I/O by
executing callbacks when events (such as I/O operations) are completed, without
waiting for them to finish.
9. Hard: What is the purpose of the “this†keyword in JavaScript, and how
does it behave in arrow functions?
Answer: this refers to the current context in JavaScript. Arrow functions do not
have their own this context; they inherit it from the surrounding code.
10. Hard: Explain the concept of promises in JavaScript and how they improve
asynchronous code readability.
11. Easy: What is the purpose of the let keyword in JavaScript, and how does it
differ from var?
Answer: let is used to declare block-scoped variables, while var declares variables
with function scope. let is preferable as it helps avoid certain issues related to
variable hoisting.
Answer: Middleware functions in Express.js have access to the request, response, and
the next middleware function. They can modify the request/response objects,
terminate the request, or call the next middleware in the stack.
13. Moderate: What is the purpose of the “prototype†in JavaScript, and how
is it used in object-oriented programming?
Answer: The “prototype†is an object from which other objects inherit properties
and methods. It is used in JavaScript’s prototypal inheritance, allowing objects to
share functionality.
14. Moderate: How does JavaScript handle variable hoisting, and why is it
important to be aware of it?
Answer: JavaScript hoists variable declarations to the top of their scope. It’s crucial
to be aware of hoisting, as variables can be used before their declaration, potentially
leading to unexpected behavior.
16. Hard: Explain the purpose of the “module.exports†object in Node.js, and
how is it used for exporting functions or variables.
17. Hard: Describe the differences between the “==†and “===â€
operators in JavaScript.
Answer: == is the equality operator that performs type coercion, converting operands
to the same type before comparison. === is the strict equality operator that compares
both value and type without type coercion.
18. Hard: What is the purpose of the “map†function in JavaScript, and how
does it differ from the “forEach†function?
Answer: The “map†function creates a new array by applying a function to each
element of an existing array. It returns a new array. The “forEach†function
performs an operation on each element of an array but does not create a new array.
19. Easy: What is the purpose of the const keyword in JavaScript, and how does it
differ from let?
Answer: const is used to declare variables with block scope that cannot be reassigned.
Unlike let, the value of a const variable cannot be changed once it’s assigned.
20. Easy: How do you check the data type of a variable in JavaScript?
Answer: You can use the typeof operator to check the data type of a variable. For
example, typeof myVariable returns a string indicating the type.
21. Moderate: Explain the concept of arrow functions in JavaScript and provide an
example.
Answer: Arrow functions are a concise way to write functions in JavaScript. Example:
const add = (a, b) => a + b;
22. Moderate: What is the purpose of the “async†keyword in JavaScript, and
how does it work with the “await†keyword?
23. Moderate: Describe the role of the “fetch†API in making HTTP requests in
JavaScript.
Answer: The prototype chain is a mechanism where objects inherit properties and
methods from their prototype. If a property or method is not found on the object,
JavaScript looks up the chain to find it in the prototype.
25. Hard: Compare and contrast the terms “hoisting†and “scope†in
JavaScript.
Answer: Hoisting is a mechanism where variable and function declarations are moved
to the top of their containing scope during the compilation phase. Scope defines the
visibility and accessibility of variables.
26. Hard: What is the purpose of the “IIFE†pattern in JavaScript, and how is
it used?
27. Hard: Explain the differences between the “splice†and “sliceâ€
methods in JavaScript for manipulating arrays.