Posts

Showing posts from January, 2022

Javascript Notes part-3 (Execution Context,Event Loop)

Image
Currying Currying simply means evaluating functions with multiple arguments and decomposing them into a sequence of functions with a single argument.  In other terms, currying is when a function ,instead of taking all arguments at one time, takes the first one and returns a new function, which takes the second one and returns a new function, which takes the third one, etc. until all arguments are completed. // Noncurried version const add = ( a , b , c ) => {   return a + b + c ; }; console. log ( add ( 2 , 3 , 5 )); // 10 // Curried version const addCurry = ( a ) => {   return ( b ) => {     return ( c ) => {       return a + b + c ;     };   }; }; console. log ( addCurry ( 2 )( 3 )( 5 )); // 10 There are several reasons why currying is ideal: Currying is a checking method to make sure that you get everything you need before you proceed It helps you to avoid passing the same variable again and agai...

Javascript Notes part-2 (Prototype Inheritance,Closures,Call Stack)

Image
Prototype Property In JavaScript, every function and object has a property named prototype by default.  All JavaScript objects inherit properties and methods from a prototype . If you want to add a new property or method to an existing object constructor you cannot add it dynamically,you'll have to add it to the constructor function itself. In JavaScript, a 'prototype' can be used to add properties and methods to a object constructor function. NOTE : The  Prototype property is used to provide additional properties to all the objects created from a constructor function. When you create a variable or function in javascript you automatically get acess to some in-built properties and methods,this is possible because Javascript adds those in-built properties/methods to the prototype object directly. Example function  Person(first, last, age, eyecolor) {    this . firstName  = first;    this . lastName  = last;    this . age  = age;...