Let’s face it, basic knowledge already helps a lot in the most ordinary day-to-day tasks. However, we sometimes face performance issues or other enhancements that lead us to turn to more advanced tools.
With time and practice you’ll discover little shortcuts in the language to make your day-to-day life faster and simpler. In this article,
1) Conditional shortcuts
2) ~~ Operator
You can make use of the ~~ operator instead of Math.floor(). It yields a performance gain, not to mention it’s much easier to work with and remember.
3) Resizing an Array with array.length
You can always adjust the size of the Array through Array.length, often cutting it in half or even leaving it empty.
4) Low-cost merge of arrays
When merging arrays, especially when they are very large, there is a high overhead when choosing to use Array.concat(), largely because concat() will create a third Array as a result of the operation. In this case, you can use Array.push.apply(array1, array2), which basically puts the second Array inside the first one.
5) Default value with ||
Still using the shortcuts, you can have default values in case of inconsistency in variables or parameters.
6) Calculating array.length in large structures
7) Further exploring the console
8) Accessing the Array using slice()
You can use the slice() method to access the Array at more strategic positions, such as the last ones, searching for one or more positions. You can carry this out by using negative parameters.
9) Falsy or Truly validation with the !! operator
The operator can be used to yield ‘false’ or ‘true’ results. Remember that the values 0, “”, null, undefined, NaN, as well as false will result in false.
10) Number to String and String to Number in no-time
FunctionUp is a pay after placement boot camp that trains candidates in backend engineering skills. We are a team of IIT / ISB alumni who are passionate about solving the key problem of starting a career in tech. Our boot camp addresses the skill deficiency the recent college graduates face, owing to the traditional college curriculum which has failed to keep up with the current industry trends. FunctionUp emerged from a shared understanding regarding sustainable education, which should pay for itself. Our aim is to enable and empower college graduates through our cohorts to ensure equal opportunity to all. Visit us here