InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How to calculate the Fibonacci series in JavaScript? |
|
Answer» Here's the CODE to CALCULATE the FIBONACCI series in JS code: Examplevar the_fibonacci_series = FUNCTION (n) console.log(the_fibonacci_series(9)); |
|
| 2. |
Why is the "this" operator inconsistent In JavaScript? |
|
Answer» In JavaScript, this operator always REFERS to the object, which is invoking the function being executed. So, if the function is currently being USED as an EVENT handler, this operator will refer to the NODE which FIRED the event. |
|
| 3. |
How to "deep-freeze" an object in JavaScript? |
|
Answer» To ENSURE that an object is deep-frozen, you will have to create a RECURSIVE function for freezing each property of type object: Without deep freeze. Examplelet person = { Output { name: 'Ankit', profession: { name: 'content writer' } } Now, using Deep Freeze for the object, function deepFreeze(object) { |
|
| 4. |
Is JavaScript as Pass by value or pass by reference language? |
|
Answer» Interestingly enough, it is both. Primitive types like number, string, etc. are PASSED by value, but OBJECTS can be passed-by-value (when we consider a variable HOLDING an object is a REFERENCE to the object) and ALSO as a pass-by-reference (when we consider variable to the object is holding the object itself). |
|
| 5. |
What do you mean by the Temporal Dead Zone in ES6? |
|
Answer» In ES6, Temporal Dead Zone is a behavior occurring in JavaScript while DECLARING a variable with the LET and const keywords. The period between entering the scope and being declared is the one when these keywords cannot be ACCESSED and enter the Temporal Dead Zone. Also Read: JQuery Questions |
|
| 6. |
What is the drawback of creating a true private in JavaScript? |
|
Answer» One of the drawbacks of creating a true private METHOD in JavaScript is that they are highly memory consuming. A new copy for each method is created for every instance. Example:var Employee = function (name, company, salary) { Here, while creating each variable, each instance makes a new copy of emp1, emp2, and emp3 in IncreaseSalary. Thus, MAKING it INEFFICIENT for your SERVER end. |
|
| 7. |
What is a generator in JavaScript and when to use it? |
|
Answer» In JavaScript, generators are those FUNCTIONS which can be exited and re-entered later on. Their variable bindings shall be SAVED across the re-entrances. They are written using the function* syntax. The Generator function should be used when:
JavaScript is a high-level, multi-paradigm programming language which conforms to the ECMAScript specification. Read our list of advanced javascript interview questions to get a deep understanding of this language. |
|
| 8. |
Give an example and explain the main difference between ES6 class and ES5 function constructors? |
|
Answer» The main DIFFERENCE between these two is when you are using INHERITANCE. It is much more COMPLICATED using inheritance in ES5, while the ES6 version is SIMPLE and easy to remember. ES6 Class:class Person { function Person(name) { |
|
| 9. |
What is the use of the Weakmap object in JavaScript? |
|
Answer» The WEAKMAP object is BASICALLY a collection of key or value pairs where the keys are weakly referenced. It provides a way for extending OBJECTS from the outside without meddling into the garbage collection. Here are some use cases of Weakmap objects:
|
|
| 10. |
What is asynchronous programming and why is it important in JavaScript? |
|
Answer» Asynchronous programming means that the program engine runs in an EVENT loop. Only when blocking OPERATION is required, a REQUEST is started, and the CODE runs without blocking the result. This is VITAL in JavaScript because it is a very natural fit for the user interface code and very efficient performance-wise on the server end. |
|
| 11. |
What is the significance and benefit of including 'use strict' at the beginning of a JavaScript source file? |
|
Answer» The "use strict" is not a statement, rather a literal expression that is vital to your code as it presents a way for voluntarily enforcing a stricter parsing and error handling process on your JavaScript code FILES or functions during runtime. Most importantly, it just makes your code very easy to manage. Here are some of the benefits of using use strict expression at the beginning of a JS source file:
|
|
| 12. |
How do you use map filter function in JavaScript? |
|
Answer» The MAP function returns the same number of ELEMENTS as present in the original ARRAY but the value of elements will be transformed in some way. On the other HAND, the filter function can return fewer or more elements than the original array but the value of the original elements will not CHANGE. |
|
| 13. |
How do you use the spread Operator & Spread operators? |
|
Answer» Using the REST operator we can CALL a function using any number of arguments and can be accessed as an ARRAY. It allows the destruction of an array of objects. Example of Rest operator in JavaScript function SUM(...theArgs) {
Speare operator is just the reverse of rest OPERATORS and allows to expand an iterable such as an array expression can be expanded using by dividing the array into individual elements. For example let array 1 = [3,4]; |
|
| 14. |
What are the data types used in JavaScript? |
|
Answer» The FOLLOWING are the DIFFERENT TYPES of DATA types USED in JavaScript.
|
|
| 15. |
What is Closure with example? |
|
Answer» A function that can access its parent SCOPE, even after the parent function has CLOSED is CALLED JAVASCRIPT closure. Example
var myFunc = makeFunc(); |
|
| 16. |
How to remove duplicate values in an array with JavaScript? |
|
Answer» There are two METHODS to remove duplicate CONTENT from an array such as USING a temporary array and a separate index. ExampleFUNCTION getUnique(arr){ const array = [1, 2, 3, 2, 3,4,5]; |
|
| 17. |
What is the difference between arrow functions & normal functions? |
|
Answer» 1) Using the arrow function, you can get the same RESULTS as normal functions by writing a few lines of code as shown in the example below. //Example of Regular function: // Example of Arrow function 2) In normal functions, argument binding is POSSIBLE and other HAND arrow functions have no argument binding. 3) Regular functions are construable but arrow functions are not constructible. |
|
| 18. |
What is promise in JavaScript with example? |
|
Answer» An OBJECT that shows the eventual completion or failure of asynchronous options along with its resultant value is CALLED promise in JavaScript. The possible three states of a promise are PENDING, fulfilled, or rejected. It allows handling multiple asynchronous OPERATIONS in JavaScript. A Promise has 3 states:
|
|
| 19. |
What is the difference between let, var & const? |
||||||||||||
Answer»
|
|||||||||||||
| 20. |
What is JavaScript Hoisting? |
|
Answer» A JavaScript default behavior that moves the declaration of variables and functions at the top of the current SCOPE is CALLED JavaScript HOSTING. You can USE hosting for declaration, not for initialization. Example1. Variable hoisting console.log(x); // UNDEFINED 2. Function hoisting let x = 20, y = 10; |
|
| 21. |
What is the meaning of prototype in JavaScript? |
|
Answer» A special type of enumerable object to which we can attach additional properties is called a prototype. JavaScript is a dynamic language and at any time we can add new properties to an object and can be shared among all the INSTANCES. Hence to add new properties and implement inheritance prototypes are USED. 2. What is a callback function?A function passed as an argument to another function is called a callback function and this technique ALLOWS a function to call another function. A callback function gets EXECUTED after the execution of another function gets finished. Examplefunction myDisplayer(some) { function myCalculator(num1, num2, myCallback) { myCalculator(5, 5, myDisplayer); |
|