Basic Mapping
Basic Mapping
String Transformation:
2. Given an array of strings, capitalize the first letter of each string using map().
3. Given an array of objects representing people with name and age properties, create a new
array containing only the names of these people using map().
4. Given an array of numbers, create a new array where each element is the original number
multiplied by its index in the array using map().
5. Given an array of numbers, create a new array containing only the even numbers, and
double each even number using map().
6. Given a 2D array of numbers, transform it into a new 2D array where each number is
squared using map().
7. Given an array of strings, filter out the strings that contain fewer than 5 characters, and
capitalize the first letter of each remaining string using map().
8. Given an array of numbers, create a new array where each number is replaced by "even" if
it's even, and "odd" if it's odd using map().
9. Given an array of strings, transform each string to uppercase and then append " - LENGTH:
{length}" to each string, indicating its length, using map().
10. Rewrite any of the above examples using arrow functions within the map() method.
11. Given an array of objects representing products with name and price properties, filter out
the products with a price greater than $50.
12. Given an array of strings, filter out the strings that have a length greater than 5 characters.
Filter by Number Range:
13. Given an array of numbers, filter out the numbers that are greater than 100 and less than
1000.
14. Given an array of objects representing students with name, age, and grade properties, filter
out the students who are younger than 18 and have a grade lower than 80.
15. Given an array of objects representing employees with name, age, and department
properties, filter out the employees who are older than 30 and work in the "Sales"
department.
16. Given an array of numbers, filter out the duplicate numbers, so the resulting array contains
only unique values.
17. Given an array containing various data types (such as strings, numbers, booleans, null,
undefined), filter out the falsy values (e.g., empty strings, zero, false, null, undefined).
18. Given two arrays of numbers, filter out the numbers that are common to both arrays.
19. Given two arrays of numbers, filter out the numbers that are present in the first array but
not in the second array.
20. Given an array of strings, filter out the strings that match a specific regular expression
pattern.
1. Write a function that takes an array of numbers and returns a promise that resolves with
the sum of all numbers in the array.
2. Create a function that accepts an array of promises and returns a promise that resolves
with an array of their resolved values.
3. Implement a function that takes an array of URLs and fetches them asynchronously using
promises, returning a promise that resolves with an array of response data.
5. Create a function that accepts an array of file paths and reads them asynchronously using
promises, returning a promise that resolves with an array of file contents.
1. reversing using for loop
4. oru array ll korch number athil eathoke number add add cheythal ann oru value kittuka
ennulath kanan eg. [2,4,6,8,9,7,15] ithil eathoke numbers add cheythal ann 21 kittuka aa
numbers printcheyyuka
6. array reverse cheyyuka puthiya oru variable create cheyyathe swapping method
8. odd number square cheyyukayum even number cube cheyyukayum cheyyuka in a array
11. oru arrayile 1-100 ll prime numbers oke square cheyuka baaki ullath normal ayit print
cheyyuka
12. array 1-10 ll even numbers true ennum odd numbers false ennum kanikuka
13. array list even or odd numbers remove chyth print cheyyuka like filter
14. [2,4,6,8,9,7,15]. 2 square cheyyuka 4 cube cheyyuka 6 square cheyyuka 8 cube like
angane array ith thanne avanam enn illa
15. pinne count kanuka [2,6,3,4,2,1,6,5,7,8,8,6,5,9,0,5] ith oru array out kittendath duplicate
ellemnts eathanennum ethra indennum like output = (6:3,2:2,5:2,8:2)ingane
Primitive Data Types: String, Number, Boolean, Null, Undefined, Symbol, and BigInt. They are
immutable and stored by value.
Non-Primitive Data Types: Objects (including arrays, functions, etc.). They are mutable and
stored by reference.
null vs undefined:
NaN:
A way to opt-in to a restricted variant of JavaScript by adding "use strict"; at the beginning of
a script or function. Helps catch common coding errors and "unsafe" actions.
typeof Operator:
Type of Errors:
let vs var:
let: Block-scoped.
const vs let:
const: Block-scoped and immutable (the binding itself is immutable, not the value).
Type of Scope:
Block Scope:
Variables declared inside a block {} with let or const are confined to that block.
Scope Chain:
Hierarchy of scopes used to resolve variable references. Functions can access variables from
their own scope and outer scopes.
Shadowing:
Declaring a variable in a local scope with the same name as a variable in an outer scope.
Hoisting:
JavaScript's behavior of moving variable and function declarations to the top of their
containing scope during compilation.
The time between entering a block and the declaration being processed, where accessing a
variable results in a ReferenceError.
Lexical Scope:
Scope determined by the physical structure of the code, where nested functions have access
to variables declared in their outer scope.
Lexical Environment:
An environment containing the bindings of identifiers to their values in the lexical scope.
Functions
Function Statement:
Function Expression:
Anonymous Function:
Function expression with a name. Example: const foo = function bar() {};
Arrow Functions:
Concise syntax for function expressions. They do not have their own this. Example: const foo
= () => {};
This Keyword:
Function Object:
Function Constructors:
Creating a function dynamically. Example: const sum = new Function('a', 'b', 'return a + b');
Generator Functions:
Functions that can pause and resume execution using yield. Example: function* gen() { yield
1; yield 2; }
Factory Function:
Pure Functions:
Functions that return the same result given the same inputs and have no side effects.
apply: Calls a function with a given this value and arguments provided as an array.
Currying:
Transforming a function with multiple arguments into a series of functions each taking a
single argument.
Closures:
Functions that have access to their own scope, outer function’s scope, and the global scope.
Advanced Functions and Promises
Promise:
Promise States:
Promise Chain:
Promise Create:
Creating a new promise. Example: new Promise((resolve, reject) => { /* code */ });
Async/Await:
Callback Hell:
Event Loop:
Micro Tasks:
Tasks that are processed after the currently executing script and before the next rendering.
Event Delegation:
Event Bubbling: Event propagates from the target element to the root.
Event Listeners:
JS Engine Working:
Executes JavaScript code, often through Just-In-Time (JIT) compilation.
V8 Engine:
Event Handling:
Event Capture:
Event Propagation:
String Methods:
Common methods: charAt, concat, includes, indexOf, slice, split, toLowerCase, toUpperCase,
trim.
map: Creates a new array with the results of calling a function for every array element.
reduce: Executes a reducer function on each element, resulting in a single output value.
filter: Creates a new array with all elements that pass the test implemented by the provided
function.
Map vs ForEach:
Set, WeakSet:
Map, WeakMap:
WeakMap: Collection of key-value pairs where keys are objects held weakly.
Deep Copy vs Shallow Copy:
Object-Oriented Programming
Prototype:
Prototypal Inheritance:
Classical Inheritance:
Constructor:
Special method for creating and initializing an object created with a class.
Prototype Chain:
Object Methods:
Object Function:
Object Destructuring:
Extracting properties from objects into variables. Example: const {a, b} = obj;
Object.defineProperty vs defineProperties:
Object.fromEntries vs Object.entries:
ES6 Features:
New features like let, const, arrow functions, template literals, destructuring, classes,
modules.
Template Literals:
Destructuring:
Arrow functions have a shorter syntax and lexically bind the this value.
Rest Operator:
Spread Operator:
Default Parameters:
Symbols:
BigInt:
Optional Chaining:
Asynchronous JavaScript
Synchronous vs Asynchronous:
Event Loop:
Callbacks:
Functions passed as arguments to be executed after an operation completes.
Promises:
Async/Await:
Advanced Topics
Cookies: Stores data with an expiration date, sent to server with every HTTP request.
Service Worker:
Script that runs in the background, enabling features like push notifications and background
sync.
Web APIs:
Browser APIs for interacting with the web, like fetch, localStorage.
Axios vs Fetch:
Tree Shaking:
Polyfills:
Code that provides modern functionality on older browsers that do not support it.
Web applications that use modern web capabilities to deliver app-like experiences.
Zone.js:
Library that helps track asynchronous operations and improve error handling in Angular.
Miscellaneous
NaN:
Indicates "Not-a-Number".
IsNaN:
Regular Expressions:
Math Functions:
Math.random():
Unary Operators:
Ternary Operator:
Bitwise Operators:
Comma Operator:
Evaluates each operand from left to right and returns the value of the last operand.
Example: let a = (1, 2, 3); // a = 3
Eval:
Executes a string of JavaScript code. Use with caution due to security risks.
Uneval:
Instanceof:
Event Queue:
Default Parameters:
Nested Templates:
Enhanced Objects:
Shorthand property names, method definitions, and computed property names introduced
in ES6.
Precedence:
Accessors:
Languages where variables do not have a fixed type and can change types dynamically.
How does the this keyword behave in different contexts, such as in global scope, object
methods, and arrow functions?
Explain the concept of "hoisting" and how it affects variable and function declarations.
What is the event loop, and how does it affect asynchronous code execution in JavaScript?
How do setTimeout and setInterval work, and what are the differences between them?
Discuss the different ways to create objects in JavaScript and the advantages/disadvantages
of each.
What are "IIFE" (Immediately Invoked Function Expressions) and their typical use cases?
How does the apply, call, and bind methods work, and how do they differ from each other?
Explain the concept of promises and how they are used to handle asynchronous operations.
How do async/await work, and how do they simplify working with promises?
Describe the various ways to handle errors in JavaScript (try-catch, promise rejections, etc.).
How does the JavaScript engine optimize performance through techniques like JIT (Just-In-
Time) compilation?
What are Map and Set, and how do they differ from regular objects and arrays?
Describe the concept of "debouncing" and "throttling" in JavaScript and their use cases.
What is the purpose of the Symbol type, and how is it used in JavaScript?
Explain the concept of "dynamic typing" and how it affects JavaScript variables and
functions.
How do JavaScript modules work, and what are the differences between CommonJS and ES6
modules?
What are the new features introduced in the latest ECMAScript specifications (e.g.,
ES6/ES2015, ES7/ES2016, etc.)?
Explain how the Object.create() method works and its use cases.
How can you use JavaScript's Proxy and Reflect objects to intercept and redefine operations
on objects?
Describe the WeakMap and WeakSet types and their use cases.
What is the purpose of the Reflect API, and how does it interact with JavaScript's
metaprogramming capabilities?
How do class and constructor work in JavaScript, and how do they relate to prototypal
inheritance?
What are "generators" and "iterators," and how are they used in JavaScript?
Explain how the Promise.all(), Promise.race(), and Promise.any() methods work and their use
cases.
What are "decorators" in JavaScript, and how can they be used with classes and methods?
How do JavaScript's import and export statements work, and how do they support module
loading?
Explain how the Function.prototype methods like bind, call, and apply modify the behavior
of functions.
What is the "prototype chain," and how does it affect object inheritance in JavaScript?
Describe the WeakRef and FinalizationRegistry objects and their use cases in JavaScript.
How does JavaScript's event delegation work, and why is it useful for optimizing event
handling?
Explain the concept of "shadowing" in the context of variable scope and closures.
What is the difference between var, let, and const in terms of scoping and hoisting?
How can you create a "singleton" pattern in JavaScript, and what are its benefits and
drawbacks?
Describe how the fetch API works and its advantages over XMLHttpRequest.
How can you use JavaScript to create and manage web workers for concurrent execution?
What are the differences between synchronous and asynchronous JavaScript, and how do
they affect program execution?
Explain the role of async and await in handling asynchronous code and their impact on code
readability.
What is "functional programming" in JavaScript, and how can concepts like "map", "filter",
and "reduce" be used?
How do JavaScript's Array.prototype methods like find, some, and every work, and what are
their use cases?
Describe how localStorage, sessionStorage, and cookies differ in terms of persistence and
usage.+
How does the concept of "polymorphism" apply to JavaScript's type system and function
behavior?