MERN stands for MongoDB, Express, React, Node, after the four key technologies that make up the stack. MERN Stack Interview Part 11 Javascript Questions.
Q101. What is the difference between slice and splice?
The Slice() method Returns the subset of original array.
let arrayIntegers = [1, 2, 3, 4, 5];
let arrayIntegers1 = arrayIntegers.slice(0,2); // returns [1,2]
The splice() method is used either adds/removes items to/from an array, and then returns the removed item.
const fruits = [“Ram”, “Sham”, “Sita”, “Geeta”); fruits.splice(2, 2, “Radha”, “Rani”);
The first parameter (2) defines the position where new elements should be added & second parameter (2) defines how many elements should be removed. The rest of the parameters (“Radha”, “Rani”) define the new elements to be added.
Q102. What is the difference between == and === operators?
== : compares the value of the variables
===: compares the type and value of the variables
For example, 5 == “5” will return a true result. Both variables have the same value; therefore, the result will be true.
On the other hand, 5 === “5” will return a false result. Even though the value of both variables is the same, their type is not; one of them is a String (“5”), and the other one is an Integer (5).
Q103. What are lambda or arrow functions?
An arrow function is a shorter syntax for a function expression & does not have its own this, arguments, super, or new.target. These functions are best suited for non-method functions & they cannot be used as constructors.
Q104. What is the purpose of the let keyword?
The let statement declares a block scope local variable.
let number = 15;
if (number === 15){
let number = 16; console.log(number); // 16
}
console.log(number); // 15
Because the variable in if block won't exist here.
Q105. What is the reason to choose the name let as a keyword?
let is a mathematical statement that was adopted by early programming languages like Scheme and Basic. It has been borrowed from dozens of other languages that use let already as a traditional keyword as close to var as possible.
Q106. What is the Temporal Dead Zone?
The Temporal Dead Zone is a behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a let or const variable before its declaration causes a ReferenceError. The time span when that happens, between the creation of a variable’s binding and its declaration, is called the temporal dead zone.
function demo() {
console.log(counter 1); // undefined
console.log(counter2); // ReferenceError
var counter1 = 1;
let counter2 = 2;
}
Q107. What is IIFE(Immediately Invoked Function Expression)?
IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.
The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e. If you try to access variables with IIFE then it throws an error.
Q108. What is the benefit of using modules?
There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are:
1. Maintainability
2. Reusability
3. Namespacing
Q109. What are closures?
A closure is the combination of a function and the lexical env. within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables. The closure has three scope chains
1. Own scope where variables defined between its curly brackets
2. Outer function’s variables
3. Global variables
function Welcome(name){
var greetingInfo = function(message){ console.log(message+''+name);
}
return greetingInfo;
}
var myFunction = Welcome('John');
myFunction('Welcome "); //Output: Welcome John
myFunction('Hello Mr."); //output: Hello Mr.John
Q110. What are modules?
Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor.
MERN Stack Interview Part 11. MERN Stack Interview MongoDB Express React Node Javascript.
Read Also: MERN Stack Interview Questions & Answer Series Part 10