# 10 Most Important JavaScript Interview Problems

--

Hello javaScript programmers, after learning javaScript we all want to get ourselves into a dream job. In a certain position, we start to find a suitable job for us. I must say it’s a very crucial moment for a developer to face an interview. So many confusions, nervousness pull us into depression. Let’s make it a bit easier for you. Some common javaScript problems will make you confident to face a job interview.

**1. Find the largest element of an array**

Suppose, you have an array with your class test marks of all students of the class. Now you want to find the topper. As we are programmers, we are too lazy to work. We want to solve everything with our codes. Now let’s see how can we find the topper by writing a short JavaScript program.

Here, at first, we assume that the first element of the array is the topper by declaring* *** max = marks[0] **then, run a for loop till the last element by

**Between the for loop, we put the mark in a variable called**

*array.length.***. Next, we checked if the element is greater than the current max mark, then replace the previous max with the current. Thus, after the loop ends we got our desired topper.**

*element***2.Remove duplicate item from an array**

Okay now, let’s think about your naughty friend. In the class, the teacher wants to serve chocolate to all of you. So he wants you to write your name on white paper. But your naughty friend has written his name twice. Now here is a problem to find his name and remove it for the second time. Okay, now you can write a javascript program to find him easily and remove the duplication of his name.

in the above solution, the name Arif has a duplication. To remove it, firstly, we have declared an empty array to store the unique names after removing the duplication. Then, a for loop will run until the array ends. We stored the names into uniqueName array by checking that if it has a duplication or not, If the name has no duplication then its index will -1. So, only if the index matches with -1 then the number will store in uniqueName array.

**3. Count the number of words in a string**

You are playing a game with your friends something called ‘Limited words’ here you need to express your feelings with the minimum number of words. Now here arise a problem, how can we count the words. As a programmer, we don’t want to work too much to count the words one by one. So, let’s write a JavaScript program to solve the problem.

okay, let’s easily explain this. How we recognize a word in a sentence? Each word is separated with a single white space. So if we count those spaces of the sentence, then we can easily get the number of words. Let’s do it. There is a string in the variable named speech. We ran a for loop through the string and checked if there is a white space or not or the if there any double spaces between the words. After that, if there is a white space and there is no double space then the word will count by the variable count.

**4.Reverse a string**

Assume you are on a different planet of our solar system. And there are Aliens around you. Suddenly you realize that they are talking in reverse language. How will you handle this situation! Let’s solve it with JavaScript.

let’s make a function with a parameter that will receive a string. After that, a for loop will run through each letter of the string. And arrange it as the sequence like, the first letter will be added on the last index of the new string.

Now let’s talk about some mathematical problems

**5.Factorial of a number using for loop**

The **factorial** function says to multiply all whole numbers from our chosen number down to 1.

Examples: 4! = 4 × 3 × 2 × 1 = 24.

NOTE:The factorial loop will start from 1. Because (Something * 0 = 0)

# 6. Factorial of a number using **recursive function**

**7. Fibonacci Series using a for loop**

The sequence of numbers, starting with zero and one, is created by adding the previous two numbers. For example, the early part of the sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,144, 233, 377, and so on.

NOTE:Fibonacci loop will always start from 2 and the first 2 elements will hardcoded. ex: [0,1]

**8. Fibonacci series in a recursive way**

**9. Check whether a number is a Prime Number or not**

A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself

# 10. Check whether a number is an Even/Odd

A number that is divisible by 2 and generates a remainder of 0 is called an even number. An odd number is a number that is not divisible by 2. The remainder in the case of an odd number is always “1”.