Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Practice: Private Data and IIFE

A function factory returns a new function that remembers the factory arguments thanks to a closure. An IIFE is a function expression called immediately: (function () { ... })().

Task

Write a factory createFilter(property, value) that returns a function checking whether object[property] === value, and a factory createWeightConverter(multiplier) that returns a function multiplying a weight in kilograms by multiplier. Then use an IIFE to create a counter dinoCounter with a private variable count and the methods increment(), decrement() and getValue().