Javascript Interview Question

Common Javascript interview question with answer

1. Tall me About JavaScript?

Ans: Javascript is a lightweight Object-Oriented programming language. Which used for client-side scripting and validation. It’s introduced in 1995 when it supports only the Netscape navigator browser. Then it’s adopted all kinds of other browsers. it mostly features interact webpage directly without page reloading. Although Javascript has no connectivity with java programming.

2. key features of javascript?

Ans: Some of the features of javascript are:

  • Interpreted Programming language.
  • Open source Cross-Platform

3. Disadvantages of javascript?

Ans: Some of the disadvantages of Javascript.

  • No support multi-process.
  • It can’t be used for networking applications.

4. What is an argument object?

Ans: Javascript Function accepts arguments is an array-like object accessible. Inside the functions that contain the values of the arguments passed to that function.

function func1(a, b, c) {
// expected output: 1
// expected output: 2
// expected output: 3
func1(1, 2, 3);

5. How anonymous function assigned to a variable?

Ans: assign a variable and set it’s value an function without naming.

const display = () => {
console.log("anonymous function");

6. What is closure in Javascript?

Ans: When a variable value defined outside the scope and access from some inner scope. This time create a closure.

7. Is javascript case sensitive language?

And: Yes, Javascript is a case sensitive language.

8. What Is the main difference between window and document?

Ans: Window is that global object that holds global variables, function, location, history everything is under it. the document represents the DOM and DOM is the object-oriented representation of the HTML markup.

9. Does Javascript synchronize?

Ans: Yes

10. Does Javascript allow multiple spaces?

Ans: No it’s ignored multiple spaces.

11. What are the differences between null and undefined?

Ans: undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is assigned a value. it can be a representation of no value.

12. What are the differences between == and ===?

Ans: The ‘==’ operator tests for equality it doesn't check necessary type conversions. But the ‘===’ operator to check strict equality. if the two values are not of the same type when compared, it will return false.

13. How would you compare two objects in JavaScript?

JSON.stringify(obj1) === JSON.stringify(obj2)

14. How do I redirect to another webpage?

Ans:window.location = "";

15. How do you get query string values?

Ans: We can use URLSearchParams which is simple and has decent browser support.

const urlParams = new URLSearchParams(;
const myParam = urlParams.get('myParam');

16.How to call a function when the DOM is ready for it.

Ans: With jQuery, the excellent function.

17. How to convert a JSON string into an object?

Ans:1953JSON.parse(jsonString) is a complete JavaScript method to resolve this problem.

18. How to Find the child element of the parent?

Ans: The children property returns an array of elements

<div class="parent">
<div class="child1">
<div class="child2">
let parent = document.querySelector('.parent');
let children = parent.children; // [<div class="child1">]

19. How do you Get the current origin?

Ans: Use JavaScript’s built-in window.location object.
window.location.origin //

20. How do you get the object’s keys and return them into an array?

Ans: Useing javascript built-in Object.keys method.

const obj1 = {
name: "Jobayer Hossain",
id: 21,
const keys = Object.keys(obj1);
// ["name", "id"];

21. How do you toggle a class name?

Ans: Useing javascript toggle methods.

const el = document.querySelector('.title')
// true and false

22. What is Closure?

Ans: closure is a function defined inside another function and should reach to the variable which is represented and defined in the parent function scope.

23. How to empty an array in JavaScript?

Ans: There are a couple of ways by which we can empty an array,

var arrayList =  ['a', 'b', 'c', 'd', 'e', 'f'];//Method 1
arrayList = [];
//Method 2
arrayList.length = 0;
//Method 3
while(arrayList.length) {

24. What is negative infinity?

Ans: Negative Infinity is a number in JavaScript that can be obtained by dealing with negative numbers by zero.

25. Which company developed JavaScript?

Ans: Netscape.

26. Cookie

Question: How to delete a cookie?

document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";

27. Local storage & Session storage

Question: What is the difference between Local storage & Session storage?

  • it’ will stay until manually cleared.
  • Storage has an expiration time

28. innerHTML & innerText

Question: Difference between innerHTML & innerText?

29. NaN

Question: What is NaN?

30. DOM

Question: What is DOM?

31. Event

Question: How work?


Question: What is Hoisting?

33. Use strict

Question: What does use strict it do?

34. Backtick

Question: What are Template Literals?

35. Attributes and properties

Question: What is the difference between Attributes and properties?

36. BOM and DOM

Question: What is the difference between BOM and DOM in JavaScript?

  • DOM- DOM is a Document Object Model in a JavaScript that helps to access document and HTML elements. When a web page is loaded the browser creates a DOM for the page. All the objects on the page all arranged in an order.

37. Delete keyword

Question: How to add and remove properties from objects?

38. Continue statement

Question: What does JavaScript continue statement?


Question: What are the common Errors in JavaScript?

  1. Runtime Error
  2. Logic Error

40.Runtime Errors

Question: What is Runtime Errors?

Javascript Codeing Problem with Solution

The most helpful way to learn anything is through practice and exercise questions. I Hope, these workouts encourage you to increase your JavaScript coding experiences.

Image by Arek Socha from Pixabay

41. Word Count

Question: How do you count a word in a string?

const word = "waiting for changes before restart";function wordCount(text) {
const trim = text.trim();
return trim.split(" ").length;

42. Sentences Count

Question: How do you count how many sentences in a string?

function senCount(str) {
let count = 0;
str.split("").map((x) => {
x == "?" || x == "!" || x == "." ? count++ : count;
return count;
const string = "Lorem ?Ipsum ! is simply dummy text.";

43. Vowel Finding

Question: Write a program to find how many vowels exist in a string?

function vowelCount(str) {
const vowelList = "aeiouAEIOU";
let count = 0;
str.split("").map((x) => vowelList.indexOf(x) !== -1 && count++);
return count;
vowelCount("The quick brown fox");

44. Remove Duplicate

Question: How do you remove duplicate values from an array?

const array = ["Mike", "Mike", "Nancy", "Nancy", "Carl"];function removeDuplicates(arr) {
const newArray = []; => {
newArray.indexOf(x) === -1 && newArray.push(x);
return newArray;
//[ 'Mike', 'Nancy', 'Carl' ]


Question: How to check a word is a palindrome?

function isPalindrome(input) {
const toValid = input.trim("").toLowerCase();
const reverseWord = toValid.split("").reverse().join("");
return reverseWord == input.toLowerCase().trim() ? true : false;
isPalindrome(" madam ");

46. Recursive number

Answer: The count down will stop when the next n is zero, since, we add an if status as regards:

function recurse(n) {
return n < 1 ? 1 : n * recurse(n - 1);

47. Generate Even number

Question: Generate EvenNumber within Positive numbers.

function eNumber(n) {
let nums = [];
for (let i = 1; i <= n; i++) {
let ele = i * 2;
return nums;
//[ 2, 4, 6, 8, 10 ]

48. Array Item Remove

Question: How can I remove a specific item from an array?

const array = [2, 5, 9];console.log(array);const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
// array = [2, 9]

49. Object Property Remove

Question: How do I remove a property from a JavaScript object?

var myObject = {
"name": "JO\obayer",
"id": "234",

50. Array Value Check

Question: How do I check if an array includes a value in JavaScript?

console.log(['joe', 'jane', 'mary'].includes('jane')); //true

Front End Developer