Skip to content

Instantly share code, notes, and snippets.

export function format(value, formatter) {
const formatted = formatter(value);
return formatted;
}
function formatString (value) {
return value.toUpperCase()
}
function formatNumber(value) {
const departments = {
engineering: {
budget: 500000,
headcount: 45,
location: "Building A",
},
marketing: {
budget: 300000,
headcount: 20,
location: "Building B",
const franchises = {
theGodfather: {
book: {
year: 1969,
author: 'Puzo',
title: 'The Godfather'
},
original: {
budget: 7200000,
director: 'Coppola',
const originals = {
theGodfather: {
budget: 7200000,
director: 'Coppola',
title: 'The Godfather'
},
theHobbit: {
author: 'Tolkien',
year: 1937,
title: 'The Hobbit'
const media = {
theGodfather: {
budget: 7200000,
director: 'Coppola',
title: 'The Godfather'
},
theHobbit: {
author: 'Tolkien',
protagonist: 'Bilbo',
price: 20,
const theHobbit = {
author: 'Tolkien',
protagonist: 'Bilbo',
pages: 300,
title: 'The Hobbit'
}
const theMatrix = {
budget: 63000000,
director: 'Wachowskis',
title: 'The Matrix'
const theHobbit = {
author: 'Tolkien',
protagonist: 'Bilbo',
pages: 300
}
const theMatrix = {
budget: 63000000,
director: 'Wachowskis',
title: 'The Matrix'
const alpha = {
budget: 63000000,
director: 'Wachowskis',
title: 'The Matrix'
}
const beta = {
budget: 7200000,
director: 'Coppola',
title: 'The Godfather'
const theHobbit = {
author: 'Tolkien',
protagonist: 'Bilbo',
pages: 300
}
const watchmen = {
author: 'Moore',
protagonist: 'Rorschach',
pages: 450
# Questions
## 1. JavaScript
Explain the concept of closures in JavaScript and provide a scenario where they might cause memory leaks if not handled properly.
## 2. TypeScript
How would you type a function that accepts either a string or number and returns the same type that was passed in?