JavaScript Interview Questions And Answer Built-in JavaScript Methods – Part 4. Explore essential JavaScript topics including built-in methods, data structures (Map, Set), JSON, local storage, and ES6 modules. A must-read guide for frontend and full-stack developer interviews.
🧰 JavaScript Interview Questions And Answer Built-in JavaScript Methods

46. What are some commonly used Array methods in JavaScript?
map()
: Creates a new array by transforming elements.filter()
: Filters elements based on a condition.reduce()
: Reduces array to a single value.forEach()
: Executes a function on each element.
const nums = [1, 2, 3, 4];
const doubled = nums.map(n => n * 2); // [2, 4, 6, 8]
47. What are important String methods in JavaScript?
charAt()
includes()
indexOf()
slice()
split()
replace()
toUpperCase()
,toLowerCase()
const str = "JavaScript";
console.log(str.includes("Script")); // true
48. What are Object utility methods?
Object.keys()
Object.values()
Object.entries()
Object.assign()
Object.freeze()
const obj = { a: 1, b: 2 };
console.log(Object.entries(obj)); // [['a', 1], ['b', 2]]
🧠 JavaScript Data Structures
49. What is a Map in JavaScript?
Answer:Map
holds key-value pairs and remembers the original insertion order of the keys. Keys can be of any type.
const map = new Map();
map.set("name", "Alice");
map.set(123, "ID");
50. What is a Set in JavaScript?
Answer:Set
is a collection of unique values. Duplicate values are automatically removed.
const set = new Set([1, 2, 2, 3]);
console.log(set); // Set { 1, 2, 3 }
51. Difference between Map and Object?
Feature | Map | Object |
---|---|---|
Key Types | Any (object, primitive) | Only string or symbol |
Order | Ordered | Unordered |
Performance | Better for frequent additions/removals | General usage |
52. What is the difference between Set and Array?
Feature | Set | Array |
---|---|---|
Duplicates | No | Yes |
Order | Yes | Yes |
Access | No index-based access | Index-based access |
📦 JSON and Local Storage
53. What is JSON in JavaScript?
Answer:
JSON (JavaScript Object Notation) is a format to store and exchange data.
const obj = { name: "John", age: 30 };
const jsonStr = JSON.stringify(obj);
const parsed = JSON.parse(jsonStr);
54. What is localStorage in JavaScript?
Answer:localStorage
allows storing key-value pairs in the browser with no expiration.
localStorage.setItem("name", "Alice");
console.log(localStorage.getItem("name")); // Alice
55. Difference between localStorage and sessionStorage?
Feature | localStorage | sessionStorage |
---|---|---|
Expiration | Never (manual removal) | When tab is closed |
Scope | Entire origin | Per tab/session |
📂 JavaScript Modules
56. What are ES6 modules in JavaScript?
Answer:
ES6 modules allow you to break up your code into separate files.
// utils.js
export function add(a, b) {
return a + b;
}
// main.js
import { add } from './utils.js';
57. What is the difference between export default
and named export?
// Default export
export default function greet() {}
// Named export
export const sayHi = () => {};
- Default export: Only one per file.
- Named export: Multiple per file.
58. Can you use CommonJS and ES6 modules together?
Answer:
Not directly. CommonJS (require
) is used in Node.js; ES6 modules (import
) in modern browsers. Tools like Babel or Webpack can transpile between them.
🔧 Best Practices and Coding Standards
59. What are some JavaScript best practices?
- Use
let
andconst
instead ofvar
. - Avoid polluting global scope.
- Use arrow functions for callbacks.
- Use descriptive variable names.
- Write pure functions when possible.
- Avoid deep nesting.
- Use
===
instead of==
.
60. Why should you avoid global variables in JavaScript?
Answer:
Global variables can lead to naming collisions and hard-to-track bugs, especially in larger apps.
61. What is the use of strict mode
in JavaScript?
"use strict";
function test() {
x = 10; // ReferenceError in strict mode
}
It prevents the use of undeclared variables and other unsafe practices.
JavaScript Interview Questions And Answer Built-in JavaScript Methods – Part 4
🧠 Real-World Coding Questions
62. Reverse a string in JavaScript.
function reverse(str) {
return str.split("").reverse().join("");
}
63. Check if a string is a palindrome.
function isPalindrome(str) {
return str === str.split("").reverse().join("");
}
64. Find the maximum number in an array.
const arr = [5, 1, 9];
console.log(Math.max(...arr));
65. Flatten a nested array.
const nested = [1, [2, [3, [4]]]];
console.log(nested.flat(Infinity)); // [1, 2, 3, 4]
✅ Up Next: Part 5
In the final part (Part 5), we’ll cover:
- Asynchronous JavaScript (Promises, async/await, callbacks)
- Event loop and microtask queue
- JavaScript memory management
- JavaScript security practices
- JavaScript interview tips and preparation checklist