Top 15 Important JavaScrip Interview Questions and Answers Practice

Top 15 Important JavaScrip Interview Questions and Answers Practice

JavaScript is one of the most used programming languages and used to create engaging and dynamic websites. Due to its vast scope, javaScript interviews can be challanging, However, thorough preparation can help ovecome these challenges. An Interviewee should familliarize themselves with the most basic concepts to the most comples libraries and frameworks.

Here the top and most used 15 Javascript Interview Question and Answer will help an interviewee to thoroughly practice and prepare for their interview.

Basic To Advance JavaScript Coading Questions

Basic Javascript questions cover concepts like data types, variables and scopping, array, string manipulation, OOP , control flow, error handling, DOM manipulation, and asynchronous programming. The basic javaScript coading interview Question are there :

Question 1. Create a function is it take arry and resutn sum of all array

const totalSum = (numbers)=>{

    return numbers.reduce((acc, current)=>acc + current , 0)
}

let number = [20,40,56,0,34,32,23]

console.log(totalSum(number))

Question 2. Write a function that reverses a string. (Explation split string split with array and reverse array and join is use to array join to string)

const reverseString = (str)=>{
    return str.split("").reverse().join("")
}

let string = "abcd"

console.log(reverseString(string))

Question 3. Create function to reverse number. (Explain first we need to create number to string and then follow-up spliting with array and reverse method and and join method to join arran and convert to again in number with number method.

const reverseNumber = (num) =>{
    let numberstr = num.toString()
    return numberstr.split("").reverse().join("")
}
let rnumber = 12345678
console.log (reverseNumber(rnumber))

Question 4. Create a function that finds the maximum number in an array of numbers. (Explain we use javaScript array method Math.max(). and pass array with spread operator).

const maxNumber = (numberarray)=>{
    return Math.max(...numberarray)
}
number = [20,40,56,90,34,32,23]
console.log(maxNumber(number))

Question 5. Create a function that generates a random integer between a given minimum and maximum value (Explain we create a function that contain two parameters min and max and use important javascript method Math.floor and Math.random)

const generateRandomNumber = (min, max)=>{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(generateRandomNumber(1, 10))

Question 6. Write a function that removes duplicate values from an array. (Explain we use array method Array.from(new Set(arr)).

const removeDuplicateValue = (arr)=>{
    return Array.from(new Set(arr))
}
let arr = ["apple", "Mango", "Banana", "Pineapple", "apple", "Mango", "Papaya"]

console.log(removeDuplicateValue(arr))

Question 7. Implement a function that counts the number of occurrences of a given element in an array.

const addArrayGivenNumber = (numbers, target)=>{
    let solution = numbers.reduce((acc, current)=> target ? target + current : acc + current, 0)
    return numbers , target, solution
}
number = [2,4,6,4,6,3,2,3,7,3,2,4]
console.log(addArrayGivenNumber(number))

Question 8. Create a function that checks if a given year is a leap year.

const CheackLeapYear = (year)=>{
    if(year % 4 == 0){
    return "yes this is a leap Year"    
    }else{
        return "this is not a yeap year"
    }
}
console.log(CheackLeapYear(2004))

Question 9. Implement a function that sorts an array of numbers in ascending order.

const DecendingOrder = (arr)=>{
    let noDuplicate = Array.from(new Set(arr))
    return noDuplicate.sort((a, b)=>(a - b))
}
number = [23,23,43,54,64,12,543,12,543,12]

console.log(DecendingOrder(number))

Qeustion 10. Define a read-only property with a fixed value

let Student = {}

Object.defineProperty(Student, 'StudentId', {
    value : 1234
})
Object.defineProperty(Student, 'Name', {
    value : "Mohammad Aman"
})
Object.defineProperty(Student, 'EmailId', {
    value : "mohd.aman9267@gmail.com"
})
console.log(Student.EmailId)

Question 11 Create function to find a factorial number.

const Factorial = (n)=>{
    if(n == 1 || n == 0){
        return 1
    }
    return n * Factorial(n-1)
    
}

console.log(Factorial(5))

Question 12. Write a JavaScript function to calculate the sum of two numbers.

const add = (num1 = 1, num2 = 1) => {
  return num1 + num2;
};

console.log(add(5, 6));

Question 13. Write a JavaScript function that takes an array of numbers and returns a new array with only the even numbers. 

const arrayNumber = new Array(34,54,34,2,3,23,34,53,654,45,34,23,56,57,56,354,34,43,56,76,56,6,78,98);

const FilterEven = (number) => {
  const filtered = number.filter((n) => {
    return n % 2 === 0;
  });
  return filtered;
};

console.log(FilterEven(arrayNumber));

Question 14. Given an array of numbers, write a function to find the largest and smallest numbers in the array. 

const arrayNumber = new Array(34,54,34,2,3,23,34,53,654,45,34,23,56,57,56,354,34,43,56,76,56,6,78,98);

function findMinMax(arr) { 

    let min = Math.min(...arr); 
  
    let max = Math.max(...arr); 
  
    return [min, max]; 
  
  }

  console.log(findMinMax(arrayNumber));

Question 15. Write a function that sorts an array of numbers in ascending order. 

const ascendingSort = (numbers)=> { 

    return numbers.sort((a, b) => a - b); 
  
}
console.log(ascendingSort(number));

If you liked this article, then please subscribe to our YouTube Channel for useful videos. You can also find us on Twitter and Facebook.

About the author

Mohd Aman

Hi, I'm Mohd Aman, a passionate and results-driven SoftwareDeveloper. I've been actively involved in designing, developing, and delivering innovative software solutions. Ithrive on challenges and enjoy collaborating with talented teams to create cutting-edge products that have a positive impact on people's lives.

Write a Reply or Comment

Your email address will not be published. Required fields are marked *

No Comment

This post has not been commented yet.

The Webography