Java Script Interview Questions
100 Interview Questions for Freshers 1 -2 Experienced Candidates

Java Script Interview Questions
1. What is JavaScript?
JavaScript is a very powerful client-side scripting language. JavaScript is used mainly for enhancing the interaction of a user with the webpage. In other words, you can make your webpage more lively and interactive, with the help of JavaScript.
JavaScript is also being used widely in game development and Mobile application development.
2. Enumerate the differences between Java and JavaScript?
Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all interdependent and are designed for different intents.
Java is an object-oriented programming (OOPS) or structured programming languages like C++ or C, whereas JavaScript is a client-side scripting language.
3. What are JavaScript Data Types?
Following are the JavaScript Data types:
- Number
- String
- Boolean
- Object
- Undefined
4. List some features of JavaScript.
Some of the features of JavaScript are:
- Lightweight
- Interpreted programming language
- Good for the applications which are network-centric
- Complementary to Java
- Complementary to HTML
- Open source
- Cross-platform
5. Who developed JavaScript, and what was the first name of JavaScript?
JavaScript was developed by Brendan Eich, who was a Netscape programmer. Brendan Eich developed this new scripting language in just ten days in September 1995.
At the time of its launch, JavaScript was initially called Mocha. After that, it was called Live Script and later known as JavaScript.
Learn Java Script From Our Expert Trainer
6. List some of the advantages of JavaScript.
Some of the advantages of JavaScript are:
- Server interaction is less
- Feedback to the visitors is immediate
- Interactivity is high
- Interfaces are richer
7. How to create an object in JavaScript?
Objects are the building blocks of modern JavaScript and are more of a reference data type.
Object Creating Ways | Code |
Object() | var d = new object(); |
Object.create () | Var a = Object.create(null); |
Function Constructor | var Obj = function(name) {
this.name = name } var c = new Obj(“Hi”); |
8. What is the method to change the title of a page using JavaScript?
Generally, the page title varies based on the HTML document and the element structure. We can give id to an element and use code:
document.getElementById(‘page-title-id’).innerHTML=NewTitle;
9. Tell some of the widely used JavaScript testing frameworks.
This is one of the popular JavaScript interview questions for freshers.
Some of the widely used JS Frameworks are –
- Mocha
- Jest
- Jasmine
- Karma (Test Runner)
- Nightwatch
- Puppeteer (Node Library)
10. Define some of the most prevalent JavaScript operators.
In JavaScript, operators are the symbols that help in performing different operations on the given data.
- Arithmetic operators (+, -, *, /, %, ++, –)
- Comparison operators (==, ===, !=, <,>, >=,<=)
- Assignment operators (=, +=, -=, *=)
- Logical operators – for
var a=10, b=20;
(a !=b) && (a<b); // RETURNS TRUE
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
11. Define a named function in JavaScript.
The function which is named at the time of definition is called a named function. For example
- function msg()
- {
- document.writeln(“Named Function”);
- }
- msg();
12. Name the types of functions
The types of function are:
- Named – These types of functions contain names at the time of definition. For Example:
- function display()
- {
- document.writeln(“Named Function”);
- }
- display();
- Anonymous – These types of functions don’t contain any name. They are declared dynamically at runtime.
- var display=function()
- {
- document.writeln(“Anonymous Function”);
- }
- display();
13.Define anonymous function
It is a function that has no name. These functions are declared dynamically at runtime using the function operator instead of the function declaration.
The function operator is more flexible than a function declaration. It can be easily used in place of an expression. For example:
- var display=function()
- {
- alert(“Anonymous Function is invoked”);
- }
- display();
14. Difference between “ == “ and “ === “ operators.
Both are comparison operators. The difference between both the operators is that “==” is used to compare values whereas, “ === “ is used to compare both values and types.
Example:
var x = 2;
var y = “2”;
(x == y) // Returns true since the value of both x and y is the same
(x === y) // Returns false since the typeof x is “number” and typeof y is “string”
15. Difference between var and let keyword in javascript.
Some differences are
- From the very beginning, the ‘var’ keyword was used in JavaScript programming whereas the keyword ‘let’ was just added in 2015.
- The keyword ‘Var’ has a function scope. Anywhere in the function, the variable specified using var is accessible but in ‘let’ the scope of a variable declared with the ‘let’ keyword is limited to the block in which it is declared. Let’s start with a Block Scope.
- In ECMAScript 2015, let and const are hoisted but not initialized. Referencing the variable in the block before the variable declaration results in a ReferenceError because the variable is in a “temporal dead zone” from the start of the block until the declaration is processed.
Learn Java Script From Our Expert Trainer
16. What are some of the JavaScript data types?
Generally, there are 7 data types in JavaScript:
- Number let n =789;
- String let str = “Hello”;
- Boolean (‘True’ and ‘False’)
- Null let gender = null;
- Undefined (for unassigned values)
- Objects and Symbols (for complex data structures)
- Typeof operator (returns type of argument)
17. Describe different types of errors present in JavaScript.
In JavaScript, there are three different types of errors in programming.
- Parsing errors – Also called Syntax errors, these errors occur at interpretation time in JavaScript. It only affects the tread in which this error occurs, leaving other threads unaffected.
- Run-time errors – Errors that appear at the time of execution and are also defined as exceptions.
- Logical errors – These are some of the most difficult types of errors and occur whenever there are flaws in logic that drive the script. Catching these errors is a very difficult task.
18. Can you redirect a page to another page using JavaScript? How?
Yes, it is possible to redirect a page to another page or URL using JavaScript by using location, replace, and location.assign.
19. Define closure.
In JavaScript, we need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.
- var num = 10;
- function sum()
- {
- document.writeln(num+num);
- }
- sum();
20. How to use an external JavaScript file?
I am assuming that the js file name is message.js, placing the following script tag inside the head tag.
- <script type=”text/javascript” src=”message.js”></script>
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
21. What is the use of isNaN function?
isNan function returns true if the argument is not a number; otherwise, it is false.
22. What is the difference between Primitives and Objects in JS?
In JavaScript, values are of two types – Primitives and Objects. Some common differences between both are:
Objects | Primitives |
Mutable at the time of coding | Immutable |
Have a unique identity | No individual identity |
Compared by reference | Compared by Value |
23. What do you mean by strict mode in javascript and characteristics of javascript strict-mode?
In ECMAScript 5, a new feature called JavaScript Strict Mode allows you to write code or a function in a “strict” operational environment. In most cases, this language is ‘not particularly severe’ when throwing errors.
In ‘Strict mode,’ however, all forms of errors, including silent mistakes, will be thrown. As a result, debugging becomes a lot simpler. Thus programmer’s chances of making an error are lowered.
Characteristics of strict mode in javascript
- Duplicate arguments are not allowed by developers.
- In strict mode, you won’t be able to use the JavaScript keyword as a parameter or function name.
- The ‘use strict’ keyword is used to define strict mode at the start of the script. All browsers support strict mode.
- Engineers will not be allowed to create global variables in ‘Strict Mode.
24. Explain Higher Order Functions in javascript.
Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
Higher-order functions are a result of functions being first-class citizens in javascript.
Examples of higher-order functions:
function higherOrder(fn) {
fn();
}
higherOrder(function() { console.log(“Hello world”) });
function higherOrder2() {
return function() {
return “Do something”;
}
}
var x = higherOrder2();
x() // Returns “Do something”
25. What do you understand about the prompt() method?
Whenever you want to display a dialog with an optional message that prompts the user to input some text, the prompt() method is used. All major browsers including Google Chrome, Internet Explorer, and Firefox., support this
Learn Java Script From Our Expert Trainer
26. In JavaScript, what is the ‘This’ keyword?
In JavaScript, the keyword ‘this’ refers to the object it belongs to and gives different values depending upon its usage.
For Example:
- In method – refers to own object
- Alone – refers to the global object
- Function – undefined (in strict mode)
27. What are the types of JavaScript Function Scope?
The scope circumscribes the variable’s visibility. Talking about JavaScript, functions are first-class objects holding properties like an object.
The only difference is that these functions can be called, unlike other objects. JavaScript covers majorly two types of Function Scope:
- Local Scope – Variables defined inside the functions are called local to the process.
- Global Scope – The outside area of all functions is considered international.
28. What is the difference between JavaScript keywords – var and let.
In JavaScript, var and let are used for variable deceleration, but var is known as function scope whereas, let is known as block scoped.
29. What do you mean by Hoisting in JS?
The concept of hoisting stands for uplifting the variable and functions on the top of their scope before the code execution takes place.
In the JavaScript mechanism, no matter wherever the functions are declared, they are taken on the topmost position, immaterial of their scope – global or local.
30. Name a few built-in methods.
JavaScript has several built-in methods which are classified as:
- Number Methods – constructor(), toExponential(), toFixed()
- Boolean Methods – toSource(), toString(), valueOf()
- Date Methods – Date(), getFullYear(), getHours()
- Math Methods – abs(), exp(), log()
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
31. Which symbol is used for comments in Javascript?
// for Single line comments and
/* Multi
Line
Comment
*/
32. What is the use of a history object?
The history object of a browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history.
- history.back() – It loads the previous page.
- history.forward() – It loads the next page.
- history.go(number) – The number may be positive for forward, negative for backward. It loads the given page number.
33. What do you mean by Self Invoking Functions?
Without being requested, a self-invoking expression is automatically invoked (initiated). If a function expression is followed by (), it will execute automatically. A function declaration cannot be invoked by itself.
Normally, we declare a function and call it, however, anonymous functions may be used to run a function automatically when it is described and will not be called again. And there is no name for these kinds of functions.
34. What is the difference between exec () and test () methods in javascript?
- test () and exec () are RegExp expression methods used in javascript.
- We’ll use exec () to search a string for a specific pattern, and if it finds it, it’ll return the pattern directly; else, it’ll return an ’empty’ result.
- We will use a test () to find a string for a specific pattern. It will return the Boolean value ‘true’ on finding the given text otherwise, it will return ‘false’.
35. What is DOM in JS?
DOM stands for Document Object Modeling, which is a language allowing dynamic accessing and modifying the content in any document. Level of abstractions DOM has in JavaScript:
- DOM Level 1
- DOM Level 2
- DOM Level 3
- Scalable Vector Graphics
- Mathematical Mark-up Language
Learn Java Script From Our Expert Trainer
36. What is BOM in JS?
BOM stands for Browser Object Model. It is an extensive representation of elements provided by the browser like documents, location, history, and frames exposed to JavaScript.
It includes the properties and methods for JavaScript to interact with the web browser. The window is the top-level object in the BOM, representing the browser window.
It contains all other browser objects, including the properties and methods that can be used to control the Web browser. The important BOM objects are documents, history, screen, navigator, location, and frames.
You can call all the functions of the window by specifying the window or directly. To access the document, one can use a code document or window. document.
37. What is a JavaScript string?
Whenever we want to store or manipulate text, we use JavaScript strings. We need JavaScript String methods to work with strings.
38. In JavaScript, what does an Anonymous function do?
The function that has no defined name is called an anonymous function in JavaScript. One can easily use this function by replacing expressions.
This anonymous function can also be assigned to a variable. Further, this function can also be moved as an argument to a different function.
39. In JavaScript, how can you validate null or empty values?
This is one of the top Javascript interview questions and answers for freshers.
It is essential to check the condition that any user has added any value in the given field. The below code will help:
// If the length is 0 then imitate helper message
function required(inputtx)
{
if (input.value.length == 0)
{
alert(“message”);
return false;
}
return true;
}
40. List some of the Design Patterns in JS.
Whenever somebody wants to reuse solutions for regularly occurring problems in software designing, Design Patterns will solve the purpose.
The latest Design Patterns in JS are:
- Module Design pattern
- Revealing Module pattern
- Prototype Design pattern
- Revealing Prototype pattern
- Observer Design pattern
- Singleton
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
41. Define the usage of Set objects in JavaScript.
Set objects in JavaScript are the source to store elements having unique values, including both primitive as well as the object reference values.
42. Explain Deep vs. shallow object copying in JavaScript.
- Deep Coping – This means that all the values of the existing/original variables are copied to a new variable, and thus, disconnected from the existing variables.
- Shallow Coping – When commanded for shallow coping, not all the existing variables are disconnected, and some of the values or sub-values are still connected to the original.
43. What is the difference between ViewState and SessionState?
- ‘ViewState’ is specific to a page in a session.
- ‘SessionState’ is specific to user-specific data that can be accessed across all web application pages.
44. What is the === operator?
=== is called a strict equality operator, which returns true when the two operands have the same value without conversion.
45. How to read and write a file using JavaScript?
There are two ways to read and write a file using JavaScript
- Using JavaScript extensions
- Using a web page and Active X objects
Learn Java Script From Our Expert Trainer
46. How to formulate a cookie using JS?
A cookie is a set of data saved on the computer and accessed by the browser.
Step to create a JavaScript cookie :
document.cookie = “cookiename=John”; expires = date”;
47. Once a cookie is created, how to read a cookie using JS?
In the case of JavaScript, cookies can be read as:
Var x = document.cookie;
48. In HTML, how many ways are there to involve JS?
For this javascript interview question, your reply should be –
There are three ways to include JavaScript in HTML:
- Sandwich the JavaScript code by defining a pair <script></script> tags of HTML
- Create an external JavaScript file to define <script src=”Script.js”></script> in HTML
- Directly code the JavaScript into HTML element
49. How to create objects in JavaScript?
There are 3 ways to create an object in JavaScript.
- By object literal
- By creating an instance of Object
- By Object Constructor
Let’s see a simple code to create an object using object literal.
- emp={id:102,name:”Rahul Kumar”,salary:50000}
50. What is called Variable typing in Javascript?
Variable typing is used to assign a number to a variable. The same variable can be assigned to a string.
Example:
i = 10;
i = “string;”
This is called variable typing.
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer



51. What would be the result of 3+2+”7″?
Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.
52. Define isNaN in JS.
isNaN is a function that determines whether a value is NaN (not-a-number) or not. It is used for defining a function true if in case the argument is not a number. returns true if the value equates to NaN. Otherwise, it returns false.
Syntax:
isNaN(value)
53. Which method is used to remove focus from the specified object in JS?
The Blur method removes focus from the specified object in JS.
54. How to enable Strict mode in JS?
In JavaScript programming language, when strict mode is enabled, it adds compulsions. This function is used for solving some of the mistakes hindering the efficiency of the JavaScript engines. The code is:
functions myfunction()
{
“use strict”,
var v = “ Strict Mode Enabled”;
}
55. What is event bubbling in terms of JS?
Event bubbling, as well as event capturing, is one of the widely used terminologies in JS, and that is why interviewers compulsorily ask the meaning of this jargon.
In JS, the Event Flow process is evolved by three concepts:
- Event capturing
- Event Target
- Event Bubbling
The event starting from the target element to its parent element and further-reaching its ancestors is called event bubbling. Generally, all the browsers have event bubbling as their default flow of the event.
Learn Java Script From Our Expert Trainer
56. If you need to calculate the Fibonacci series in JS, what will you do?
Fibonacci series is a pattern in which each given value is the sum of the previous two, and it starts with 0,1.
Method:
- use function fib(n),
- Declare var a=0 and b=1
- Use this condition (var i=0; i<n; i++)
- Use var temp = a+b;
- Next make a=b
- And b=temp;
- }
- Return a;
The series will come like 0,1,1,2,3,5…
57. Define the output for *2 in JS.
NaN will be the output as *2 is undefined.
58. What are screen objects and their properties?
Objects used to read the information available on the client’s screen are called screen objects. Some of the properties are:
- AvailHeight
- AvailWidth
- ColorDepth
59. Explain pop() and shift() methods
The pop() method removes the last element from an array and returns it. The display on which it is called is then altered. The pop() method is similar to the shift() method.
The difference is that the Shift() method works at the array’s start. The shift () method removes an item from the beginning of an array and returns the removed item.
In both methods, the length of the array is changed. The return value of the pop and shift methods is the removed item.
Pop() example: Remove the last element of an array:
var fruits = [“Apple”, “Orange”, “Banana”, “Strawberry”];
fruits.pop();
Output:
Before pop: Apple, Orange, Banana, Strawberry
After pop: Apple, Orange, Banana
Shift() example: Remove the first element of an array:
var fruits = [“Apple”, “Orange”, “Banana”, “Strawberry”];
fruits.shift();
Output:
Before shift: Apple, Orange, Banana, Strawberry
After shift: Orange, Banana, Strawberry
60. What will be the output of the following code? var Employee = { company: ‘abc’ } var Emp1 = Object.create(employee); delete Emp1.company Console.log(emp1.company);
The output of the given code will be abc.
In the given code, the prototype property of Emp1 object is company. The delete operator will not delete the prototype property.
Emp1 object does not have a company as its own property. But the company property can be deleted directly from the Employee object using delete Employee.company.
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
61. What is the role of the event.preventDefault() method?
Fibonacci series is a pattern in which each given value is the sum of the previous two, and it starts with 0,1.
Method:
- use function fib(n),
- Declare var a=0 and b=1
- Use this condition (var i=0; i<n; i++)
- Use var temp = a+b;
- Next make a=b
- And b=temp;
- }
- Return a;
The series will come like 0,1,1,2,3,5…
62. How to check if the event.preventDefault() method was used in an element?
If we use the event.preventDefault() method, it will return a boolean indicating that event.preventDefault() was called in a particular element.
63. How can you check if the event.preventDefault() method was used in an element?
When we use the event.defaultPrevent() method in the event object returns a Boolean indicating that the event.preventDefault() was called in a particular element.
64. In JavaScript, append a new element at the end of the array.
To append an element in a JavaScript array, we use push(), and to remove an array, pop() is used.
Syntax:
array.push(item1, item2, …, itemX)
65. Empty an Array in JS.
Several ways to empty an array:
- arrayList = []
- length = 0;
- while(arrayList.length)
{
arrayList.pop();
}
Learn Java Script From Our Expert Trainer
66. What will the statement declare? var myArray = [[[]]];
It will declare that it’s a three-dimensional array.
67. Define Escape character in JavaScript.
If you want to write some special character without overlapping the application, the escape character will do the task. The backslash character (the escape characters) is used for employing special characters (‘’, “”, ‘, &)
Example: document. write “I am a “healthy” girl”
68. Give the output of the below code: var Output = (function(a) { Delete A; return A; } )(0); console.log(output);
The output will be 0.
As ‘A’ is a local variable and not an object, delete operators leave local variables unaffected.
69. How do we add/remove properties to objects dynamically in JS?
We can add a property to an object by using:
object.property_name =value
To delete a property, we can use:
object.property_name
Example:
let user = new Object();
// adding a property
user.name=’John’;
user.age =22;
console.log(user);
delete user.age;
console.log(user);
70. How to get the inner Html of an element in JS?
To get the inner Html of an element in JavaScript, we can use the InnerHTML property of the HTML DOM.
Example:
This is inner Element
<script type=”text/javascript”>
var inner= document.getElementById(“inner”).innerHTML ;
console.log(inner); // Inner Element
document.getElementById(“inner”).innerHTML = “Html changed!”;
var inner= document.getElementById(“inner”).innerHTML ;
console.log(inner); // Html changed!
</script>
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
71. What is the procedure to remove duplicate values from a JSarray?
First, we can check whether a duplicate value exists or not by using array.indexOf method. Let’s see the given example to remove duplicate values.
let duplicates = [‘Spain’,’Russia’,’Russia’,’China’,’America’,’New Jersey’];
function removeDuplicatesValues(arr){
let unique_array = [];
for(let i = 0;i < arr.length; i++){
if(unique_array.indexOf(arr[i]) == -1){
unique_array.push(arr[i])
}
}
return unique_array
}
console.log(removeDuplicatesValues(duplicates));
72. What are all the types of Pop up boxes available in JavaScript?
- Alert
- Confirm and
- Prompt
73. What is the use of Void (0)?
Void(0) is used to prevent the page from refreshing, and parameter “zero” is passed while calling.
Void(0) is used to call another method without refreshing the page.
74. What are escape characters?
Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes, and ampersands. Place backslash before the characters to make it display.
Example:
document. write “I m a “good” boy.”
document. write “I m a \”good\” boy.”
75. How to validate email in JavaScript?
- <script>
- function validateemail()
- {
- var x=document.myform.email.value;
- var atposition=x.indexOf(“@”);
- var dotposition=x.lastIndexOf(“.”);
- if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){
- alert(“Please enter a valid email address \n atpostion:”+atposition+”\n dotposition:”+dotposition);
- return false;
- }
- }
- </script>
- <body>
- <form name=”myform” method=”post” action=”#” onsubmit=”return validate email();”>
- Email: <input type=”text” name=”email”><br/>
- <input type=”submit” value=”register”>
- </form>
Learn Java Script From Our Expert Trainer
76. What is the possible way to give a comment?
Syntax:
Single line comment – // Single-line comments.
Multiple line comments – /* Multi Line Comment
77. Mention HTML DOM mouse events.
Following are the HTML DOM mouse events:
- onclick
- ondblclick
- mouseout
- mouseover
- Mouseup
- mousemove
- mousedown
Check out the 10 Most-Popular Programming Languages
78. How do we get the primitive value of a string in?
In Javascript, we can use the valueOf() method to get the primitive value of a string.
Syntax:
var myVar= “Naukri”
console.log(myVar.valueOf())
79. How do we create an array?
Following are three different ways to create an array in Javascript:
- By array literal
usage:
var myArray=[value1,value2…valueN]; - By creating instance of Array
usage:
var myArray=new Array();
By using an Array constructor
usage:
var myArray=new Array(‘value1′,’value2′,…,’valueN’);
80. What is the possible way to give default arguments in function?
Syntax:
function print(arr = [], direction = ‘A1`) {
document.write(‘Array Printing’, arr, direction)
}
print([1, 2, 3, 5])
print([1, 2, 3], ‘A2’)
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
81. What is the procedure to merge two arrays?
Syntax:
var arr1 = [1,2,3]
var arr2 = [4,5,6,7]
var mergedArrays = […arr1, …arr2]
document.write(‘Merged arrays’, mergedArrays)
82. How do we target a particular frame from a hyperlink?
We can target a particular frame from a hyperlink by consisting of the name of the required frame and can use the ‘target’ attribute in it.
<a href=”/newpage.htm” target=”newframe”>>New Page</a>
83. Name the method we can use to read and write a file in JavaScript?
JavaScript extensions can be used to read and write a file such as for opening of a file –
fh = fopen(getScriptPath(), 0);
84. Explain what are Screen objects?
Screen objects hold information from the client’s screen. It is also used to display screen width, pixelDepth, height, etc. Let’s look at the properties of screen objects-
- AvailWidth: Provides the width of the client’s screen
- AvailHeight: Provides the height of the client’s screen
- ColorDepth: Provides the bit depth of images on the client’s screen
- Width: Provides the total width of the client’s screen, including the taskbar
- Height: Provides the total height of the client’s screen, including the taskbar
85. Which keywords are used to handle exceptions?
Try… Catch—finally is used to handle exceptions in the JavaScript
Try{
Code
}
Catch(exp){
Code to throw an exception.
}
Finally{
Code runs either it finishes successfully or after catch
}
Learn Java Script From Our Expert Trainer
86. Explain “use strict”.
In Javascript, “use strict” is used to enforce the code in strict mode where we can’t use any variable without declaring it. “use strict” was not considered by earlier versions of Javascript.
87. How do we convert Javascript date to ISO standard?
To convert Javascript data to ISO standard, we can use the toISOString() method. It will convert a JavaScript Date object into a string, using the ISO standard.
Syntax:
var date = new Date();
var n = date.toISOString();
console.log(n);
88. Explain the difference between attribute and property?
Attributes provide details about elements such as ID, type, and value. Property is the value assigned to the property. It includes type=”text”, value=’Name’, and more.
89. Can we do 301 redirects in JavaScript?
We cannot do 301 redirects in JavaScript as it totally runs on the client machine. 301 is the response code that is sent by the server as a response.
90. Explain what is a callback in JS.
A callback is used as a JavaScript function transferred to some method as an argument or option. It can make events like if any state is matched then can trigger some other function.
Explore the top PHP Interview Questions and Answers
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version
Learn Java Script From Our Expert Trainer
91. When can we use JSON.stringify()?
We use this method to convert JavaScript JSON data to a string.
92. What is functional programming?
Functional programming is a programming paradigm that involves software development based on fundamental principles such as avoiding the shared state, composing pure functions, and avoiding mutable data and side effects.
It is declarative instead of imperative.
93. What is a pure function?
A pure function when given the same input will always return the same output without any side effects. These functions are essential for React+Redux apps, functional programming, and reliable concurrency.
They are completely independent of the outside state and are immune to the entire class of bugs that have to do with the shared mutable state. They are easy to reorganize in the code which makes programs more flexible and adaptable to future changes.
94. What is Memoization in JS?
Memoization is a kind of caching system where the return value of a function gets cached depending on its parameters. If the parameter of that function is not changed, then it returns the cached version of the function.
95. What is the use of Constructor functions in JS?
Constructor functions are used to create objects in javascript. It is used when we want to create multiple objects having similar properties and methods.
Learn Java Script From Our Expert Trainer
96. What is negative infinity in JS?
In JS, negative infinity is a number that can be calculated by dividing a negative number by zero.
97. What are undeclared and undefined variables in JS?
In JS, undead variables are variables that do not exist in a program and are not declared. On the other hand, undefined variables are those variables that are declared in the program but have not been given any value.
98. What is the use of a WeakSet object in JavaScript?
The JavaScript WeakSet object is the type of collection that allows us to store weakly held objects. Unlike Set, the WeakSet are collections of objects only. It doesn’t contain arbitrary values. For example:
- function display()
- {
- var ws = new WeakSet();
- var obj1={};
- var obj2={};
- ws.add(obj1);
- ws.add(obj2);
- //Let’s check whether the WeakSet object contains the added object
- document.writeln(ws.has(obj1)+”<br>“);
- document.writeln(ws.has(obj2));
- }
- display()
99. What is a window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
100. What is the use of a Map object in JavaScript?
The JavaScript Map object is used to map keys to values. It stores each element as a key-value pair. It operates the elements such as search, update and delete on the basis of specified key. For example:
- function display()
- {
- var map=new Map();
- map.set(1,”jQuery”);
- map.set(2,”AngularJS”);
- map.set(3,”Bootstrap”);
- document.writeln(map.get(1)+”<br>“);
- document.writeln(map.get(2)+”<br>“);
- document.writeln(map.get(3));
- }
- display();
Want to download these Java Script Interview Questions and Answers in the form of a readable and printable PDF for your interview preparation?
Click the download button below for the PDF version