Lädt...


🔧 JavaScript interview questions & answers with code


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Top JavaScript Interview Questions and Expert Answers with Code Examples

Flatten a Nested Object

Question : Write a function to flatten a nested JavaScript object.

Code :

function flattenObject(obj, prefix = '', res = {}) {

** for (let key in obj) {**

** const newKey = prefix ? ${prefix}.${key} : key;**

** if (typeof obj[key] === 'object' && obj[key] !== null) {**

** flattenObject(obj[key], newKey, res);**

** } else {**

** res[newKey] = obj[key];**

** }**

** }**

** return res;**

}

console.log(flattenObject({ a: { b: { c: 1 } }, d: 2 }));

// Output: { 'a.b.c': 1, d: 2 }

2. Find Duplicates in an Array

Question : Write a function to find duplicate values in an array.

Code :

function findDuplicates(arr) {

** const counts = {};**

** return arr.filter(item => counts[item] ? true : (counts[item] = 1, false));**

}

console.log(findDuplicates([1, 2, 2, 3, 4, 4, 5]));

// Output: [2, 4]

3. Implement debounce
Question : Write a debounce function that limits the rate a function is called.

Code :

function debounce(func, delay) {

** let timer;**

** return function (...args) {**

** clearTimeout(timer);**

** timer = setTimeout(() => func.apply(this, args), delay);**

** };**

}

const log = debounce(() => console.log('Logged after 1s'), 1000);

log();

4. Reverse a String Recursively

Question : Write a recursive function to reverse a string.

Code :

function reverseString(str) {

** if (str === "") return "";**

** return reverseString(str.slice(1)) + str[0];**

}

console.log(reverseString("hello"));

// Output: "olleh"

5. Check for Palindrome

Question : Write a function to check if a string is a palindrome.

Code :

function isPalindrome(str) {

** const cleaned = str.toLowerCase().replace(/[^a-z]/g, '');**

** return cleaned === cleaned.split('').reverse().join('');**

}

console.log(isPalindrome("A man, a plan, a canal, Panama"));

// Output: true

Read more... ⇲

JavaScript interview questions & answers with code

JavaScript interview questions & answers with code

favicon atharvgyan.com

Explore more on Atharv Gyan ⇲

React interviews questions and answers with code

React interviews questions and answers with code

favicon atharvgyan.com

Angular interview questions

Angular interview questions

favicon atharvgyan.com

CSS Interview Questions

CSS Interview Questions along with their answers and Code

favicon atharvgyan.com
...

🔧 Commonly asked ReactJS interview questions. Here are ReactJS interview questions and answers


📈 44.68 Punkte
🔧 Programmierung

🔧 JavaScript interview questions & answers with code


📈 39.06 Punkte
🔧 Programmierung

🔧 1000 JavaScript Interview Questions & Answers


📈 35.92 Punkte
🔧 Programmierung

🔧 Some commonly asked JavaScript array-related interview questions along with their answers


📈 33.96 Punkte
🔧 Programmierung

🔧 JavaScript Closures: Top Interview Questions and Answers


📈 33.96 Punkte
🔧 Programmierung

🔧 📝 30 Essential Javascript Interview Questions, with Detailed Answers From Easy to Hard


📈 33.96 Punkte
🔧 Programmierung

🔧 JavaScript Interview Questions and Answers


📈 33.96 Punkte
🔧 Programmierung

🔧 2024 Ultimate Guide to JavaScript Interview Questions and Answers


📈 33.96 Punkte
🔧 Programmierung

🔧 JavaScript Interview Questions and Answers for the Job Market in Bangladesh


📈 33.96 Punkte
🔧 Programmierung

🔧 Javascript Interview Questions and answers


📈 33.96 Punkte
🔧 Programmierung

🔧 Top 20 Advanced JavaScript Interview Questions and Answers for Seasoned Engineers


📈 33.96 Punkte
🔧 Programmierung

🔧 Top 10 Interview Questions And Answers In JavaScript For 2025


📈 33.96 Punkte
🔧 Programmierung

🔧 Top 10 Salesforce Developer Interview Questions & Answers


📈 30.58 Punkte
🔧 Programmierung

🔧 GIT Interview Questions & Answers


📈 30.58 Punkte
🔧 Programmierung

🔧 GIT Interview Questions & Answers


📈 30.58 Punkte
🔧 Programmierung

🔧 Master Your DevOps Interview: Top 50 Questions & Answers for 2024


📈 30.58 Punkte
🔧 Programmierung

🔧 Top 40 Frontend Developer Interview Questions & Answers 2024 🪄 ❤️‍🔥


📈 30.58 Punkte
🔧 Programmierung

🔧 10 React Interview Questions & Answers


📈 30.58 Punkte
🔧 Programmierung

🔧 Top 20 React Interview Questions & Answers


📈 30.58 Punkte
🔧 Programmierung

🐧 A Listicle Of Interview Questions & Answers For Linux Admin (Updated)


📈 30.58 Punkte
🐧 Linux Tipps

🐧 Top 48 Linux Interview Questions & Answers (Updated 2020)


📈 30.58 Punkte
🐧 Linux Tipps

⚠️ Questions and Answers - Post your questions now


📈 29.7 Punkte
⚠️ Malware / Trojaner / Viren

🔧 【Interview Essentials】Common JavaScript Interview Questions


📈 28.9 Punkte
🔧 Programmierung

🔧 20 Top Situational Interview Questions and Answers


📈 28.62 Punkte
🔧 Programmierung

🔧 Real-Life Kubernetes Interview Questions and Answers with Explanations


📈 28.62 Punkte
🔧 Programmierung

🔧 HTML Interview Questions and Answers for Freshers


📈 28.62 Punkte
🔧 Programmierung

🔧 Top 5 Yii2 Interview Questions and Answers


📈 28.62 Punkte
🔧 Programmierung

📰 Top 15 Security Testing Interview Questions and Answers


📈 28.62 Punkte
📰 IT Security Nachrichten

🔧 100 AWS Interview Questions and Answers: Comprehensive Guide for Beginners and Experienced Professionals


📈 28.62 Punkte
🔧 Programmierung

🔧 30 OOPs Interview Questions and Answers (2023)


📈 28.62 Punkte
🔧 Programmierung

🔧 STAR Interview Questions and Answers: A Complete Guide


📈 28.62 Punkte
🔧 Programmierung

🔧 Top 5 Tailwind CSS Interview Questions and Answers


📈 28.62 Punkte
🔧 Programmierung

🔧 Data Science Interview Questions and Answers.


📈 28.62 Punkte
🔧 Programmierung

🔧 50 Java Interview Questions Answers for Practice


📈 28.62 Punkte
🔧 Programmierung

🔧 The Most Common .NET Interview Questions and Answers


📈 28.62 Punkte
🔧 Programmierung

matomo