Keeping this in mind we have prepared a few JS interview questions along with the answers which will surely help you in cracking the technical round during the selection process.
We will also be providing a downloadable PDF at the end of the blog post.
Let’s go through all the questions and their answers one by one:
|In JS, objects are prototype-based||In Java, the objects are class-based|
|JS doesn’t support multi-threading||Java supports multi-threading|
It is a lightweight, interpreted programming language with object-oriented abilities allowing programmers to build interactivity into otherwise static HTML pages.
Following are the data types that are supported by JS:
6. What do you understand by undeclared and undefined variables?
Undeclared variables do not exist in a program and are not declared and a runtime error is encountered, in case a program tries to read the value of such variables.
However, undefined variables are the variables declared within the program but are not assigned any value as of now.
7. Define global variables.
Variables that are defined outside of functions are called global variables. These variables can be used by any function in the program since they have a global scope, which means all functions and scripts in the program can access it.
8. What is the difference between array splice and slice methods?
The array splice method returns the removed item by adding or removing items from an array, whereas the array slice method is used to return the selected items in an array as a new array object.
In other words, the splice method is used to insert or delete items to/from an array but the slice method is used to choose certain items/elements from an array.
NULL is used to define no object or no value, its syntax is
It implies a null string, no number, no value, no object, no valid Boolean, and no array object.
11. Distinguish between “==” and “===”.
While, “===” is a strict equality test and returns “true” in case, when both the variables are of the same type and contain the same value.
For example, in the case of
null === undefined // false null == undefined // true
Type coercion refers to the implicit conversion of values from one data type to another (e.g. number to string or vice versa).
const first = '10'; const second = 20; console.log(first + second); //returns 1020
In the example above, you can see how the
second variable got converted to a
string, and then the both
second got concatenated.
13. What is passed by value and passed by reference?
14. What is a callback function?
If a function is passed into a different function as an argument, it’s called a callback function. These are of two types — synchronous and asynchronous callbacks.
15. What is JSON?
You can convert a string to a native object using
JSON.parse(text) and a native object to a string using
If you have a related query, feel free to let us know in the comments.
And, kindly share the information with your friends who you think might be interested in reading it.