2021-04-23 10:10:00
7 JavaScript Tips & Tricks That No One Teaches JavaScript is no doubt one of the coolest languages in the world and is gaining more and more popularity day by day. So the developer community has found some tricks and tips after using
JS for quite a while now.
Functional InheritanceFunctional inheritance is the process of receiving features by applying an augmenting function to an object instance. The function supplies a closure scope which you can use to keep some data private. The augmenting function uses dynamic object extension to extend the object instance with new properties and methods.
They look like: https://pastebin.com/eLLUrCZ0
.map() Substitute.map() also has a substitute that we can use which is .from(): https://pastebin.com/cZYe8Dkr
Number to string/string to numberUsually, to convert a string to a number, we use something like this: https://pastebin.com/pfVybUws
and to convert a string to a number, we use: https://pastebin.com/G2WnqaTP
but what we can use to code fast is: https://pastebin.com/fUFYQKa1
Using length to resize and emptying an arrayIn
JavaScript, we can override a built-in method called length and assign it a value of our choice.
Let's look at an example: https://pastebin.com/zjuc3L36
It can also be used in emptying an array, like this: https://pastebin.com/9tWmq0T9
Swap Values with Array DestructuringThe destructuring assignment syntax is a
JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables. We can also use that to swap values fast, like this: https://pastebin.com/DfrYjkz6
Remove duplicates from an ArrayThis trick is pretty simple. Let's say, I made an array that is containing numbers, strings, and booleans, but the values are repeating themselves more than once and I want to remove the duplicates. So what I can do is: https://pastebin.com/QJAsY9a4
Short For LoopYou can write less code for a loop like this: https://pastebin.com/UxwtuDhd
@jsoid
188 views07:10