Top 100 Java script Interview Questions & Answers

Here is the list of top 100 interview questions for JAVASCRIPT to be asked recently in all the top companies with answers.

Frequently asked Java Script Interview Questions

Q1.What JavaScript?

Answer:JavaScript is an object oriented, text based programming language commonly used in web development both on client and server side to make web page interactive. It was originally developed by Netscape as a means to add dynamic and interactive elements to websites.

Q2. What are the different data types present in JavaScript?

Answer:

  • Number
  • String
  • Boolean
  • Object
  • Undefined
  • Null

Q3. Differentiate between Java and JavaScript?

Answer:Java is a complete programming language that is an object-oriented programming or structured programming languages like C++ or C, In contrast, JavaScript is a coded program that can be introduced to HTML pages as a client side scripting language. These two languages are not at all inter-dependent and are designed for different intent.

Q4. Explain Hoisting in JavaScript?

Answer:Hoisting is a concept of JavaScript in which JS host all function expression and variables at top of the environment and because of that we can use a variable or function before declaring it.

Q5. What is Negative infinity?

Answer:NEGATIVE_INFINITY is the same as the negative value of the global object's Infinity property. This value behaves slightly differently than mathematical infinity: Any positive value, including POSITIVE_INFINITY, multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY

Q6. What is DOM?

Answer: The Document Object Model is a programming interface for web documents which represents the page so that programs can change the document structure, style, and content. As an object-oriented representation of the web page, it can be modified with a scripting language such as JavaScript.

Attend a Free Online Mock Interview

Q7. List some features of JavaScript?

Answer:

  • Light Weight Scripting, Interpreted language.
  • Dynamic Typing Functional Style.
  • Object-oriented programming support.
  • It is complementary to and integrated with Java.
  • Open, Cross platform scripting language
  • Platform Independent Prototype-based.

Q8. What are object prototypes?

Answer: Prototypes are the mechanism by which JavaScript objects inherit features from one another. It allows to easily defining methods to all instances of a particular object. 

Q9. Explain Implicit Type Coercion in JavaScript?

Answer: Type Coercion refers to the process of automatic or implicit conversion of values from one data type to another. This includes conversion from Number to String, String to Number, Boolean to Number etc. when different types of operators are applied to the values.

Q10. Difference between “==” and “===” operators?

Answer: = is used for assigning values to a variable in JavaScript. == is used for comparison between two variables irrespective of the datatype of variable. === is used for comparison between two variables but this will check strict type, which means it will check datatype and compare two values.

Q11. Explain Closures?

Answer: A closure is the combination of a function enclosed with references to its surrounding state. It gives access to an outer function's scope from an inner function.

Q12. What is NaN property in JavaScript?

Answer: NaN stands for Not a Number which represents a value that is not a valid number. It can be used to check whether a number entered is a valid number or not a number. To assign a variable to NaN value, we can use one of the two following ways. var a = NaN var a = Number.NaN.

Q13. What are undeclared and undefined variables?

Answer: Undefined: It occurs when a variable has been declared but has not been assigned with any value. Undefined is not a keyword. Undeclared: It occurs when we try to access any variable that is not initialized or declared earlier using var or const keyword.

Q14. Is JavaScript a statically typed or a dynamically typed language?

Answer:JavaScript is a dynamically typed language that it does not require the explicit declaration of the variables before they're used.

Q15. What is ‘This’ keyword in JavaScript?

Answer:‘This’ keyword is used in the global and function contexts. The behaviour of ‘This’ keyword changes between strict and non-strict modes. The type checking for dynamically typed languages is done during run time. Required Man Hours = QTY / (Productivity Rate)

Q16. Explain passed by value and passed by reference.

Answer: Pass by value means making a copy in memory of the actual parameter's value that is passed in, a copy of the contents of the actual parameter. In pass by reference (also called pass by address), a copy of the address of the actual parameter is stored.

Q17. What is an Immediately Invoked Function in JavaScript?

Answer: An Immediately-invoked Function Expression is a way to execute functions immediately, as soon as they are created and they don't pollute the global object, and they are a simple way to isolate variables declarations.

Q18. Explain call (), apply () and, bind () methods?

Answer: Call invokes the function and allows passing in arguments one by one. Apply invokes the function and allows to pass in arguments as an array. Bind returns a new function, allowing passing in this array and any number of arguments.

Q19. Which symbol is used for comments in JavaScript?

Answer:To create a single line comment in JavaScript by placing two slashes "//" in front of the code or text. For Multi line comments:-“/* is used for multi-line comment */”.

Q20.Explain Higher Order Functions in JavaScript?

Answer: Functions can be assigned to variables in the same way that strings or arrays can. They can be passed into other functions as parameters or returned from them as well. A “higher-order function” is a function that accepts functions as parameters and/or returns a function.

Q21. What is Currying?

Answer:Currying is an advanced technique of working with functions. It's used not only in JavaScript, but in other languages as well. It is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(a)(b)(c) . Currying doesn't call a function. It just transforms it.

Q22.What is memorization?

Answer: Memorization is a top-down, depth-first, optimization technique of storing previously executed computations. Whenever the program needs the result of these computations, the program will not have to execute that computation again. Instead, it will reuse the result of the previously executed computation.

Q23. What is recursion?

Answer: A recursive function calls itself, the memory for a called function is allocated on top of memory allocated to calling function and different copy of local variables is created for each function call.

Q24. What are callbacks?

Answer:A callback is a function passed into another function as an argument which is then invoked inside the outer function to complete some kind of routine or action. A good example is the callback functions executed inside a.then () block chained onto the end of a promise after that promise fulfills or rejects.

Q25. Explain Scope and Scope Chain in JavaScript?

Answer: The scope is a policy that manages the availability of variables. In JavaScript, scopes are created by code blocks, functions, modules. Scope chains establish the scope for a given function. Each function defined has its own nested scope, and any function defined within another function has a local scope which is linked to the outer function — this link is called the chain.

Q26. What is the difference between ViewState and SessionState?

Answer:The basic difference between these two is that the ViewState is to manage state at the client's end, making state management easy for end-user while SessionState manages state at the server's end, making it easy to manage content from this end too.

Q27. What is the use of a constructor function?

Answer: A constructor is a function that creates an instance of a class which is typically called an “object”. It gets called when you declare an object using the new keyword. The purpose of a constructor is to create an object and set values if there are any object properties present.

Q28. What is the working of timers?

Answer: A timer is created to execute a task or any function at a particular time. It is used to delay the execution of the program or to execute the JavaScript code in a regular time interval. With the help of timer, we can delay the execution of the code.

Q29. List some of the advantages of JavaScript?

Answer:

  • Less server interaction − validate user input before sending the page off to the server which saves server traffic, which means fewer loads on the server.
  • Immediate feedback to the visitors − don’t have to wait for a page reload to see if they have forgotten to enter something.
  • Increased interactivity − Create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
  • Richer interfaces − Use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to the site visitors.

Q30. Name the types of functions?

Answer: The types of function are:
Named function- contains name at the time of definition.
function display()  
{   
   document.writeln("Named Function");  
}  
display();  
Anonymous functions: doesn't contain any name that are declared dynamically at runtime.
var display=function() 
  {  
  document.writeln("Anonymous Function");
   }  
display();
  

Q31. What is BOM?

Answer: BOM stands for Browser Object Model that provides interaction with the browser. The default object of a browser is a window. By specifying the window or directly, we can call all the functions of the window. The window object provides various properties like document, history, screen, navigator, location, innerHeight, innerWidth.

Q32. How to create an array in JavaScript?

Answer: Create an array in JavaScript

  • By array literal
  • By creating an instance of Array
  • By using an Array constructor

Q33. What are the falsy values in JavaScript, and how can we check if a value is falsy?

Answer: Those values which become false while converting to Boolean are called falsy values.
const falsyValues = ['', 0, null, undefined, NaN, false];   
Check if a value is falsy by using the Boolean function or the Double NOT operator.

Q34. What is the use of a Number object in JavaScript?

Answer:The JavaScript number object enables to represent a numeric value which may be integer or floating-point. It follows the IEEE standard to represent the floating-point numbers.
function display()  
{   
var x=102;//integer value    
var y=102.7;//floating point value    
var z=13e4;//exponent value, output: 130000   
  var n=new Number(16);//integer value by number object   
  document.write(x+" "+y+" "+z+" "+n); 
    } 
     display(); 

Q35. What is the requirement of debugging in JavaScript?

Answer: JavaScript didn't show any error message in a browser in which these mistakes can affect the output. The best practice to find out the error is to debug the code using web browsers like Google Chrome, Mozilla Firebox. To perform debugging, we can use:

  • Using console.log() method
  • Using debugger keyword

Q36. What is this [[[]]]?

Answer: This is a three-dimensional array.
var myArray = [[[]]];  

Q37. What are the scopes of a variable in JavaScript?

Answer: The scope of a variable is the region of the program in which it is defined and JavaScript variable will have only two scopes.

  • Global Variables − It has global scope which means it is visible everywhere in the JavaScript code.
  • Local Variables – It will be visible only within a function where it is defined. Function parameters are always local to that function.

Q38.What are the rules to be followed for variable naming conventions in JavaScript?

Answer:

  • Don’t use any of the JavaScript reserved keyword as variable name. For example, break or boolean variable names are not valid.
  • JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or the underscore character. For example, 123name is an invalid variable name but _123name or name123 is a valid one.
  • JavaScript variable names are case sensitive. For example, Test and test are two different variables.

Q39. What's the way to resolve the delay in project time?

Answer:Attributes- provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.

Q40.What is a Typed language?

Answer: Typed Language is a type of language in which the values are associated with values and not with variables. It is of two types:
Dynamically: the variable can hold multiple types; like in JS a variable can take number, chars.
Statically: the variable can hold only one type, like in Java a variable declared of string can take only set of characters and nothing else.

Q41. Name some of the JavaScript Framework?

Answer: A JavaScript framework is an application framework written in JavaScript. It differs from a JavaScript library in its control flow. There are many JavaScript Frameworks available but some of the most commonly used frameworks are:

  • Angular
  • React
  • Vue

Q42. What is the difference between innerHTML & innerText?

Answer: InnerHTML – It will process an HTML tag if found in a string
InnerText – It will not process an HTML tag if found in a string

Q43. What are Exports & Imports?

Answer: Imports and exports help us to write modular JavaScript code. Using Imports and exports we can split our code into multiple files

Q44.What are escape characters in JavaScript?

Answer: Escape characters enable to write special characters without breaking the application. It is used when working with special characters like single quotes, double quotes, apostrophes and ampersands. Place backslash before the characters to make it display.

Q45. What is a prompt box?

Answer: A prompt is a type of box. It allows the user to enter their input, provide a text box, number, and text provided by label and box.

Q46. What are all the loops available in JavaScript?

Answer: The loops available in JavaScript are,
 For loop statement: It is the same as for loops of Java and C which continues until a specified condition evaluates to false.
Ex:-for(int i=0; i<=3; i++)
While loop: It executes its statement until a specified condition evaluates to true.
Ex: - while(Condition)
              Statement
 do-while loops: continues until a specified condition is false.
Ex:-do
statement
while(Condition)

Q47.What is the use of the delete operator?

Answer: The Delete keyword is used for deleting purposes which is used to delete the property as well as its value also.
Example:-
              var student= {age:20, batch:”ABC”};
              delete student.age;

Q48. Name some built-in methods in JavaScript?

Answer:

  • anchor() – Creates an HTML anchor to be used as a hypertext target
  • ceil() – returns the smallest integer that is greater than or equal to the given number
  • concat() – Combines two strings and returns the newer string
  • constructor() – Returns the function that created the corresponding instance of the object
  • Date() – Returns the present date and time

Q49. How can you read a cookie in JavaScript?

Answer: By using our JavaScript concept we can read a cookie given below:-
              var x = document.cookie;

Q50. How to handle exceptions in JavaScript?

Answer: The exception is the abnormal termination of a program is called an exception.It are caused by our program, not by our lack of system resources. An alternative way to continue the rest of the program is typically called exception handling.
  We can handle the exception with Try-catch and finally keyword, or we can say that Try-Catch block finally is used to handle exceptions in JavaScript.
Try-catch block is used to handle the exception, and the ‘finally’ block is bound to call either their call of try-catch block or not, but finally, the block is bound to call.
Syntax:-
Try{
//Code
}   
         

Q51.What do you mean by variable typing in JavaScript?

Variable typing is used for assigning a number to a variable and after that assigning string to that same variable.
              i= 8;
The steps using which you can get more clarifications are given below through an Example:-
              i= 8;
              i=”john”;

Q52. What are the different types of errors are available in JavaScript?

Answer: The three types of errors are:
Load time Errors: come up when we load a web page with inappropriate syntax Errors are otherwise known as Load time Errors.
Load time Errors are generated dynamically.
Run time Errors: are generated due to misuse of command inside an HTML language are known as Run time errors.
Logical Errors: occur due to the formation or writing off bad logic inside the program, which logic has different operations known as Logical errors.

Q53. What do you mean by unshift method in JavaScript ?

Answer:Unshift method work is similar to the push method but pushes method to append the elements and pretend the elements. It works beginning of the array. This method is used to pretend one or more than one element at the beginning of an array.

Q54. How to print Statements in JavaScript?

Answer: By using Console.log () function in JavaScript, we can print any variables defined before int, and it is also used to print any message that needs to get displayed to the user. The Syntax for defining or showing elements to the user is:-console. log(A);

Q55. What is the difference between JavaScript and Jscript?

Answer:

The difference between these two scripts is said to be no different. Both are pretty similar, but the only difference is JavaScript ids developed by Netscape and Jscript is developed by Microsoft.

Q56. Name the keyword which is used to print the text on the screen?

Answer: Write the text on the screen through the document.
 “document.write (“Welcome”);”
After that, it will write welcome on the screen.

Q57. Explain WeakMap in JavaScript?

Answer: The map is usually used to store key-value pairs. It can be both primitive and non-primitive types. If the keys and values must be always an object in weakmap. If there are no object references then the garbage collector collects the object.

Q58. What are generator functions?

Answer: Generator function helps to generate new values using the keyword yield.
The major work of the yield keyword is to pause the execution of the function in the middle send the details to the function call and resume at the state where the yield was before the interruption.
Syntax:
function* gen(){
     yield 1;
     yield 2; 
   …} 

Q59. What is the use of promises in JavaScript?

Answer:

Any asynchronous operations that occur in JavaScript is handled by promises.
There are four stages of promises in JavaScript:
  • Pending – It acts to be a waiting list neither fulfilled nor rejected. It is the initial state.
  • Fulfilled – Any Asynchronous operation is completed to ensure that the promise has been fulfilled.
  • Rejected – Asynchronous reason that’s incomplete ensures that the promise has been rejected.
  • Settled – This is a neutral state where the promise is neither rejected nor fulfilled.

Q60. What is the role of deferred scripts in JavaScript?

Answer: The parsing of HTML code during page loading is by default paused until the script has not halted executing. The webpage is delayed if the server is slow or the script is chiefly heavy. When using the Deferred, scripts would delay execution of the script until the HTML parser is operating. It decreases the web pages’ loading time and they get showcased faster.

Q61. What are the different functional components in JavaScript?

Answer: Functional components are important topics covered in a javascript Course.
Two types of functional components in JavaScript are –First-class functions and nested functions.

  • First-class functions: These functions in JavaScript are used as first-class objects. Usually, this means that such functions can be passed in form of arguments to other functions. Moreover, they are returned as values from other functions or assigned to variables, or they can be saved in data structures.
  • Nested functions: Those functions that are defined within other functions are termed Nested functions. Whenever the main function is invoked, nested functions are called.

Q62. What is ECMAScript?

Answer:ECMAScript is a scripting language standardized by ECMA International in ECMA-262. Languages like ActionScript, JavaScript, and many more scripting languages are used ECMAScript, among these JavaScript is a well know client-side scripting language and an implementation of ECMAScript, since the standard was published. The latest version is ECMAScript6.

Q63. What is the Self-Executing Function?

Answer:The self-executing function will execute right after it has been defined. The advantage of using it is, it will execute the code without declaring any global. Mostly it will be used to attach event listeners to DOM elements and another initialization work.

Q64. What are classes in JavaScript?

Answer: The templates of JavaScript objects are Classes in JavaScript
Every class in JavaScript must have a constructor with it. 
Syntax:
class ClassName 
{constructor() { … }}

Q65. Explain WeakSet?

Answer: Set is a collection of unique and ordered components in JavaScript. Weakset like Set, is a collection of unique and ordered elements, but there are certainly major differences: It only holds objects and no other types. A weakly referred item is one that is contained within the weakset. This means that if an item within the weakset lacks a reference, it will be trash collected. Unlike Set, only it has three methods add( ) , delete ( ) and has ( ).

Q66. Can we break JavaScript Code into several lines? If yes, then How?

Answer: Yes, We can break JavaScript code into several lines like within a string statement using a backslash (‘\’) at the end of the first line code.
For example, document.write (“This is \a program”);
JavaScript ignores the break in the line.
 For Example: var x=1, y=2,
z=x+y;

Q67. Write a code for adding new elements dynamically in JavaScript?

Answer: Elements Dynamically

Dynamic

Q68.How should we change the style/class of an element?

Answer:First of all, we can use the className to assign a value directly to the class. If any such classes are already present on the element, then this will override them.
For getting the value of class on the element, we can add multiple spaces using className.
We can change the class of an element:-  
  document.getElementById(“myText”).style.fontSize = “20”; or,
 document.getElementById (“myText”).className = “any class”;

Q69. How to detect the operating system on the client machine?

Answer: If we want to detect the operating system on the client machine, then we have to use navigator.appVersion or navigator.userAgent property.

Q70. What is the use of the delete operator?

Answer: The Delete keyword is used for deleting purposes. The delete keyword is used to delete the property as well as its value also.
For Example:-
              var student= {age:20, batch:”ABC”};
              delete student.age;

Q71.State the Difference between an Alert Box and a Confirmation Box?

Answer:“Alert” gives a pop-up displaying only one button, which is an “OK” button, but in the other case, the Confirmation box displays two buttons that contain one “OK” button and another one is the” CANCEL” button. This is the fundamental difference between the alert box and the confirmation box.

Q72.How should we create a cookie in JavaScript?

Answer: By using JavaScript, we can create, read, and delete (crud operations) cookies with the “document. cookie” property.
To create a cookie JavaScript:-
document.cookie = “username=John Doe”;
You can also add an expiry date for a cookie, but, by default, the expiry date of a cookie is when you close your respective browser, the cookie gets deleted or expired.

Q73.Is JavaScript contains concept level scope?

Answer: The scope is the context on where the variables for functions can be accessed, as you all write in Java and C, C++. I.e. defined by { }.
The concept level is otherwise known as block-level scope as JavaScript supports Function-level scope.
So, JavaScript does not have a concept-level scope.
Due to the variables declared inside or within the function have scope inside the function.

Q74.What are the two primary groups of data types in JavaScript?

Answer: The primary groups of data types JavaScript are mentioned below:-
Primitive Types- are number and Boolean type data types.
Reference Types: are the more complex types. It is like strings and dates.

Q75. How can Generic objects be created?

Answer:Generic objects can be created as:-
              var I = new object();

Q76. What do you mean by blur function in JavaScript?

Answer: The blur event occurs when the element losses its focus or blurriness.
The primary use of the Blur function in a program is to removing focus from a specified object
object.onblur= function(){JavaScript};

Q77.What is the use of the Push method in JavaScript?

Answer: The primary benefit of the push method is that it always adds or appends one or more than one element to the end of an array, so using this method, we can append multiple elements bypassing multiple arguments.
Syntax:-
array.push(item1,item2,……,item10);

Q78. How are the object properties assigned in JavaScript?

Answer: You can define a property by assigning its value.
All JavaScript variables like objects names and property names are case-sensitive so that we can assign value through their name and properties.
We can assign object Properties in the following ways:-
obj[“class”] = 12;

Q79. Write the various ways to get the status of a Checkbox?

Answer:The status for getting status of a checkbox as follows:-
              alert(document.getElementById(‘checkbox1’).checked);
If the Checkbox is checked, then the alert will return TRUE.

Q80. How do you debug a JavaScript code?

Answer: All modern web browsers like Chrome, Firefox, etc. have an inbuilt debugger that can be accessed anytime by pressing the relevant key, usually the F12 key. There are several features available to users in the debugging tools.

Q81. What’s the difference between let and var?

Answer: Both let and var are used for variable and method declarations in JavaScript. So there isn’t much of a difference between these two besides that while var keyword is scoped by function, the let keyword is scoped by a block.

Q82. What is the difference between Document and Window in JavaScript?

Answer: The document comes under the windows object and can also be considered as its property. Window in JavaScript is a global object that holds the structure like variables, functions, location, history, etc.

Q83. How do you empty an array in JavaScript?

Answer: There are a few ways in which we can empty an array in JavaScript: By assigning array length to 0: var arr = [1, 2, 3, 4]; arr.length = 0; By assigning an empty array: var arr = [1, 2, 3, 4]; arr = []; By popping the elements of the array: var arr = [1, 2, 3, 4]; while (arr.length > 0) {   arr.pop(); } By using the splice array function: var arr = [1, 2, 3, 4]; arr.splice(0, arr.length);

Q84. What is the difference between Event Capturing and Event Bubbling?

Answer: Event Capturing is a process starts with capturing the event of the outermost element and then propagating it to the innermost element. Event Bubbling process starts with capturing the event of the innermost element and then propagating it to the outermost element.

Q85. How do you remove duplicates from a JavaScript array?

Answer: There are two ways in which we can remove duplicates from a JavaScript array:
By Using the Filter Method
To call the filter() method, three arguments are required.
These are namely array, current element, and index of the current element.
By Using the For Loop
An empty array is used for storing all the repeating elements.

Q86. What is the reason for wrapping the entire content of a JavaScript source file in a function book?

Answer: This is an increasingly common practice, employed by many popular JavaScript libraries. This technique creates a closure around the entire contents of the file which, perhaps most importantly, creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries.
Another feature of this technique is to allow for an easy alias for a global variable. This is often used in jQuery plugins.

Q87.What would be the result of 2+5+”3″?

Answer: Since 2 and 5 are integers, they will be added numerically. And since 3 is a string, its concatenation will be done. So the result would be 73. The ” ” makes all the difference here and represents 3 as a string and not a number.

Q88.What is an event bubbling in JavaScript?

Answer: Event bubbling is a way of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. The execution starts from that event and goes to its parent element. Then the execution passes to its parent element and so on till the body element.

Q89. In how many ways a JavaScript code can be involved in an HTML file?

Answer: There are 3 different ways in which a JavaScript code can be involved in an HTML file:

  • Inline
  • Internal
  • External
An inline function is a JavaScript function, which is assigned to a variable created at runtime. You can differentiate between Inline Functions and Anonymous since an inline function is assigned to a variable and can be easily reused. When you need a JavaScript for a function, you can either have the script integrated in the page you are working on, or you can have it placed in a separate file that you call, when needed. This is the difference between an internal script and an external script.

Q90.How does Typeof Operator work?

Answer: The typeof operator is used to get the data type of its operand. The operand can be either a literal or a data structure such as a variable, a function, or an object. It is a unary operator that is placed before its single operand, which can be of any type. Its value is a string indicating the data type of the operand

Q91.What are the characteristics of JavaScript ‘Strict Mode’?

Answer:

  • ‘Strict Mode’ will stop developers from creating global variables.
  • Developers are restricted from using duplicate parameters.
  • Strict mode will restrict you from using the JavaScript keyword as a variable name or function name.
  • Strict mode is declared with ‘use strict’ keyword at the beginning of the script.
  • All browsers support strict mode.

Q92.What is a ternary operator?

Answer: The ternary or conditional is an operator that is used to make a quick choice between two options based on a true or false test. This can be used as a substitute for if…else block when having two choices that are chosen between a true/false condition.

Q93.What are the different types of Error Name values in JavaScript?

Answer: There are 6 types of Error Name values. Each one of them is briefly explained as follows:

  • Eval Error – Thrown when coming across an error in eval() (Newer JS releases don’t have it).
  • Range Error – Generated when a number outside the specified range is used.
  • Reference Error – It comes into play when an undeclared variable is used.
  • Syntax Error – When the incorrect syntax is used, we get this error.
  • Type Error – This error is thrown when a value outside the range of data types is tried to be used.
  • URI Error – Generated due to the use of illegal characters

Q94.How will you remove duplicates from a JS array?

Answer:Using Filter – It is possible to remove duplicates from an array in JavaScript by applying a filter to the same. To call the filter() method, three arguments are required. These are namely array, current element, and index of the current element.function unque_array (arr){.

Q95. How can you import all exports of a file as an object in JavaScript?

Answer: To import all exported members of an object, one can use:
import * as object name from ‘./file.js.’
The exported methods or variables can be easily accessed by using the dot (.) operator.

Q96. Explain the window.onload and onDocumentReady perform in JavaScript?

Answer: onload:-
The Window.onload will execute the codes when the browser loads the DOM tree and other resources like images and objects. It is not run further & until all the information on the page is loaded, leading to some delay before any code is executed.
.onDocumentReady:-
The .onDocumentReady is executed when the DOM is load, without waiting for the resources to load like .onload works. This leads to the .onDocumentReady allows to executes the code faster in DOM.
 In the case of .onDocumentReady, it loads the codes just after the Document Object Manipulation is loaded, so this allows early manipulation of the code.

Q97. What is an Immediately Invoked Function in JavaScript?

Answer: The function which runs as soon as its defined is known as the Immediately Invoked Function in JavaScript. 
Syntax: 
function () 
{   // Do something; 
}) (); 

Q98.What are arrow functions?

Answer: The function which allows declaring shorter syntax which was introduced during the ES6 version is known as the arrow function. Example:  Before hello = function () {  return “Hi!”;} After: hello = () => {   return “Hi!”;}

Q99.What are the rest parameter and spread operators?

Answer:The operator that allows calling a function with n number of arguments and accessing those extra arguments as an array is known as rest operator. It also allows destructuring array or objects.  As the name suggest the spread operator allows us to expand an iterable like array into its individual elements.

Q100.What is a Temporal Dead Zone?

Answer: The variables declared using keyword let or const keywords faces temporal dead zone. It is a state that occurs when the variables are tried to access before initialization.