lastminutelearnings Angular Top 20 JavaScript Coding Questions with answers | Most frequently asked coding questions for Angular Interview question | javascript coding questions and answers | easy to understand and learn | most asked javascript coding questions 2024

Top 20 JavaScript Coding Questions with answers | Most frequently asked coding questions for Angular Interview question | javascript coding questions and answers | easy to understand and learn | most asked javascript coding questions 2024

Top 20 JavaScript Coding Questions with answers | Most frequently asked coding questions for Angular Interview question | javascript coding questions and answers | easy to understand and learn | most asked javascript coding questions 2024 post thumbnail image

(Top 20 JavaScript Coding Questions with answers) Angular Developer साठी interview देत असतानी बऱ्याचदा असे होते कि आपण जे Angular Theory Questions आहेत त्यांचे उत्तर चांगले देतो परंतु interview मध्ये काही coding question देखील विचारले जातात. Angular coding question विचारले असता असे आढळते कि बरेच जण इथे समाधानकारक उत्तर देऊ शकत नाही आणि theory questions चे चांगले उत्तर देऊन पण interview मध्ये rejection ला सामोरे जावे लागते.

कधी interview देणाऱ्या candidate ला वाटते कि मी सर्व theory questions चे चांगले उत्तर दिलेत तरी फक्त कोडींग question न जमल्यामुळे माझे rejection झाले तर इथे हे क्लिअर होते कि coding question खरंच खूप महत्वाचे आहेत कारण तुम्ही दिलेल्या कोडींग answer मुळे तुमचे problem solving skill हे interviewer ला समजते. जर तुम्ही कोडींग प्रश्न नाही सोडवू शकलात तर interview घेणाऱ्याला वाटते कि थेअरी प्रश्न तुम्ही पाठ करून दिले असतील किंवा तुम्हाला exact concept काय आहे हे समजले नसेल त्यामुळे तुम्ही coding question solve करू शकले नाही.

आपण आज coding question कशा प्रकारचे विचारले जातात हे समजण्यासाठी तुम्हाला काही Most frequently asked coding questions for Angular Interview देत आहोत.

1) Given an array of numbers, use reduce to find the sum of all numbers. numbers = [1, 2, 3, 4, 5]

Answer: 
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((acc, current) => acc + current, 0);
console.log(sum); 
// Output: 15

2) use filter to return an array of only even numbers. numbers = [1, 2, 3, 4, 5]

Answer:
const numbers = [1, 2, 3, 4, 5, 6];
const evens = numbers.filter(num => num % 2 === 0);
console.log(evens); 
// Output: [2, 4, 6]

3) using map function create a new array with each number doubled

Answer:
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(num => num * 2);
console.log(doubled); 
// Output: [2, 4, 6, 8, 10]

4)using reduce method to find the sum of odd numbers only

Answer:
const numbers = [1, 2, 3, 4, 5];
const sumOdds = numbers.reduce((acc, num) => num % 2 !== 0 ? acc + num : acc, 0);
console.log(sumOdds); 
// Output: 9
Top 20 JavaScript Coding Questions with answers

5) find the maximum value in array using reduce method

Answer:
const numbers = [1, 2, 3, 4, 5];
const max = numbers.reduce((max, num) => num > max ? num : max, numbers[0]);
console.log(max); // Output: 5

6) Find an array of strings that are longer than 3 characters using filter strings = [‘a’, ‘ab’, ‘abc’, ‘abcd’]

Answer:
const strings = ['a', 'ab', 'abc', 'abcd'];
const longStrings = strings.filter(str => str.length > 3);
console.log(longStrings); // Output: ['abcd']

7)use map method to convert string to uppercase

Answer:
const strings = ['goligat', 'dhoka'];
const uppercased = strings.map(str => str.toUpperCase());
console.log(uppercased); // Output: ['GOLIGAT', 'DHOKA']
8)In given array find count occurrence of each element (Top 20 JavaScript Coding Questions with answers)
Answer:
const array = ['a', 'b', 'a', 'c', 'b', 'a'];
const countOccurrences = array.reduce((acc, item) => {
  acc[item] = (acc[item] || 0) + 1;
  return acc;
}, {});
console.log(countOccurrences); // Output: { a: 3, b: 2, c: 1 }

9) we are giving nasted array, flatten it into a single array using reduce

Answer:
const nestedArray = [[1, 2], [3, 4], [5, 6]];
const flattened = nestedArray.reduce((acc, current) => acc.concat(current), []);
console.log(flattened); // Output: [1, 2, 3, 4, 5, 6]

10)use map and reduce to find the sum of the squares of each number

Answer:
const numbers = [1, 2, 3, 4];
const sumOfSquares = numbers.map(num => num ** 2).reduce((acc, num) => acc + num, 0);
console.log(sumOfSquares); // Output: 30

11) Extract Numbers from Array of Objects

Answer:
const objects = [{ value: 1 }, { value: 2 }, { value: 3 }];
const values = objects.map(obj => obj.value);
console.log(values); // Output: [1, 2, 3]

12)Apply some coditions on each array element

Answer:
const numbers = [1, 2, 3, 4];
const allPositive = numbers.every(num => num > 0);
console.log(allPositive); // Output: true

13) find the first number greater than 3 in given array

Answer:
const numbers = [1, 2, 3, 4, 5];
const firstGreaterThanThree = numbers.find(num => num > 3);
console.log(firstGreaterThanThree); // Output: 4

14)using for loop generate the first 10 numbers of the Fibonacci sequence

Answer:
const fibonacci = (n) => {
  const result = [0, 1];
  for (let i = 2; i < n; i++) {
    result.push(result[i - 1] + result[i - 2]);
  }
  return result;
};
console.log(fibonacci(10)); // Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

15)using for loop print sum of elements in array

Answer:
const numbers = [1, 2, 3, 4, 5];
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
  sum += numbers[i];
}
console.log(sum); // Output: 15

16)Find unique numbers from array

Answer:
const array = [1, 2, 2, 3, 4, 4];
const uniqueElements = array.filter((item, index) => array.indexOf(item) === index);
console.log(uniqueElements); // Output: [1, 2, 3, 4]

17) remove duplicate elements from array

Answer:
const array = [1, 2, 2, 3, 4, 4];
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Output: [1, 2, 3, 4]

18) multiply each element in an array by 3

Answer:
const numbers = [1, 2, 3, 4, 5];
const multiplied = numbers.map(num => num * 3);
console.log(multiplied); // Output: [3, 6, 9, 12, 15]

19) using for loop reverse array

Answer:
const array = [1, 2, 3, 4, 5];
const reversed = [];
for (let i = array.length - 1; i >= 0; i--) {
  reversed.push(array[i]);
}
console.log(reversed); // Output: [5, 4, 3, 2, 1]

20)return objects where status is ‘active’

Answer:
const objects = [{ id: 1, status: 'active' }, { id: 2, status: 'inactive' }, { id: 3, status: 'active' }];
const activeObjects = objects.filter(obj => obj.status === 'active');
console.log(activeObjects); // Output: [{ id: 1, status: 'active' }, { id: 3, status: 'active' }]
Click here to prepare for angular interview questions
Click here to visit angular’s official website

Share with your friends

1 thought on “Top 20 JavaScript Coding Questions with answers | Most frequently asked coding questions for Angular Interview question | javascript coding questions and answers | easy to understand and learn | most asked javascript coding questions 2024”

Leave a Reply

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

Related Post