JKJaya Krishna Pulipatiinjkpulipati.hashnode.dev·Oct 8, 2021 · 1 min readUnary OperatorString to number conversion using the unary operator. const a = '10'; +a // will print number 10 Look at below const foo = { valueOf: () => '10' }; +foo // it will also print 1000
JKJaya Krishna Pulipatiinjkpulipati.hashnode.dev·Jun 23, 2021 · 1 min readHow to make a property of an object is read-only using typescriptReadonly<Type> It will set all the properties of Type to read-only, which means the properties of the Type cannot be reassigned. Let's see with an example so that we can understand easily interface Person { name: string, age: number } let pe...00
JKJaya Krishna Pulipatiinjkpulipati.hashnode.dev·Jun 17, 2021 · 2 min readWhen should we choose map over object literal?The map is a collection of key-value pairs like Objects. But the main difference is map allows keys of any type(primitive/non-primitive). When we try to store an object as a key in Object, it converts all keys to strings and the resulted value would ...00
JKJaya Krishna Pulipatiinjkpulipati.hashnode.dev·Jun 15, 2021 · 1 min readSort list of numbers in Javascript without using the sort method.function sortNumbers() { return arr.reduce((acc, value) => { const nextIndex = acc.findIndex(num => value > num); const index = nextIndex > -1 ? nextIndex : acc.length; acc.splice(index, 0, value); return acc; ...00