Read: Class 02 :Classes, Inheritance, Functional programming - Goorob-401-advanced-javascript/amman-javascript-401d1 GitHub Wiki

  • Functional Programming : programming with a distinction between pure code and impure code ,and modeling your solution as pure functions .

    • pure code : no side effects , the same results every time we run it

    • impure code : contains side effects , the results not same every time we run it

    • procedural : modeling your solution as sequential

    • Object Oriented : modeling your solution as communicating objects

    • Pure functions : pure because it always returns the same result if the same values are passed into also it doesn’t modify values outside of ts scope, can never mutate data, produce no side effects and can be easily reused

    • Higher order functions : a function that operates on other functions. They can take in a function as input, or return one as output. Examples: map, filter, reduce

  • Objects and Inheritance : when methods or properties are attached to object’s prototype they become available for use on that object and its descendants

    • use class and extends keywords internally JavaScript will still use prototype-based inheritance.
      • function() becomes class {}
      • call() becomes extends
  • Errors : we can also define our own errors in our programs. Error logs are kept in order to fix bugs in productions. Writing good error messages is critical for finding and fixing bugs in deployed applications

    • Writing Good Error Messages :

      • a timestamp so that a timeline of the error can be made
      • a message about the problem that occurred
      • a message about the cause of the problem
      • a consistent format (so that it can be parsed and searched)
      • a severity level (low, med high) or (0 - 10)
    • Handling Thrown Errors : a useful feature of the language that force developers to use a function correctly the idea is that the sooner the code fails, the sooner a developer will find bugs and fix them

      Programs like servers need a way to continue running in spite of bugs in the code so Javascript has a try {} catch (error) {} syntax for handling this.