function curryFunction(a) {
return function (b) {
const res = a + b
return function (c) {
return res + c
}
}
}
console.log(curryFunction(1)(2)(3))
To check if an object is null or not: _.isEmpty(obj) ? true : false; - optimized approach
Array.prototype.last = function() {
return this.length == 0 ? -1 : this[this.length - 1];
};
/**
* const arr = [1, 2, 3];
* arr.last(); // 3
*/
Array.prototype.last:
last to the Array.prototype. This means that all arrays will inherit this method and can call it directly.A lexical environment is the internal structure that JavaScript creates at runtime to keep track of:
It's created whenever a function is invoked or a block is entered.
js
CopyEdit
function outer() {
let x = 10;
function inner() {
console.log(x); // ❓ How does this work?
}
return inner;
}
const fn = outer(); // outer is done, but...
fn(); // still logs 10
Here’s what’s happening:
inner() has a lexical environment that references the outer function's environment.x = 10, even after outer() has returned — this is called a closure.JavaScript automatically allocates and deallocates memory using Garbage Collection (GC) mechanisms.
https://www.geeksforgeeks.org/memory-management-in-javascript/
Functional programming is a declarative programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. In JavaScript, it emphasizes the use of pure functions, immutability, and higher-order functions. [[1](https://medium.com/@rashmipatil24/functional-programming-in-javascript-bfc7f53b77a1#:~:text=Functional programming (FP) is a programming paradigm,its simplicity%2C maintainability%2C and ease of testing.)]