Why JS Math.random() is not perfectly random and how you can get truly random numbers.

Image for post
Image for post
Image by Gerd Altmann from Pixabay

If you are a developer who started your journey with the help of online tutorials, you would have probably used the Math.random() function in your coding projects. I used it for my dice roll application, which I created when I started learning React.

One of the main reasons for the use of the Math.random() function for random number generation is its ease of use. All you have to do is call the function and voila, you get a random number. It has no dependencies as well.

The Math.random() function can be used in several applications including animation and random background color selection. …


Start implementing efficient functions with memoization

Image for post
Image for post
Photo by Tamanna Rumee on Unsplash

One of the best things about being a software developer is that you never stop learning. There is always something to learn especially with something like JavaScript. When our applications become complex, the need for speed becomes a major deal-breaker. Performance optimization becomes a necessity when our application code grows in scale. Memoization is a concept that helps you build efficient applications even when the complexity is higher. The concept of memoization is very much associated with pure functions and functional programming in JavaScript.

You must keep in mind that memoization is merely a concept and is not dependent on JavaScript or any specific programming language. We will be looking at memoization from JavaScript’s perspective in this article.


Understand the concepts of dynamic programming

Image for post
Image for post
Photo by Arthur Lambillotte on Unsplash

Programming is a field of interest for many aspiring individuals. But more often than not, these programmers tend to skip certain fundamentals of programming. One of these fundamentals is called Dynamic Programming.

When a newbie hears the word “dynamic programming”, they would probably consider it to be a variant of programming that dynamically adjusts itself to changes in real-time. I did too…

But once you start learning the concepts of dynamic programming, you will realize that it is a fancy word for an optimization approach to programming problems.

Let’s have a better look at dynamic programming.

What is Dynamic Programming?

Dynamic programming is defined…


Write cleaner, programmer-friendly code with pure functions

Image for post
Image for post
Image by Genty from Pixabay

When you grow as a developer, it is essential that you write code that is cleaner and readable. Functional programming is a paradigm that helps you achieve this status. Pure functions are a special type of function that is a core feature of functional programming.

According to JS guru - Eric Elliot,

Functional programming (often abbreviated FP) is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and the application state flows through pure functions. …


Enabling high performant applications with caching

Image for post
Image for post
Photo by Yuiizaa September on Unsplash

Web applications have come a long way from the early days. A typical web application development goes through several stages of design, development, and testing before it is ready for release. As soon as your web app gets released, it will be accessed by real-life users on a daily basis. If your web app becomes popular, it will be accessed by at least several million users on a daily basis. Although this sounds exciting, this would incur a lot of running costs.

Apart from cost, complex calculations and R/W operations can take time for completion. This means that your user should wait for the completion of the operation which can be a bad user experience if the wait becomes too long. …


Why handle them in the first place?

Image for post
Image for post
Photo by Tanaphong Toochinda on Unsplash

What Are Errors?

Things do not always work the way you want. When something goes wrong, we get notified via an error. This error can either be thrown by the JavaScript engine or a developer.

Any developer should be quite familiar with the concept of errors. Front end developers would definitely be familiar with the alarming red text notifying errors on their browser consoles when running their web applications.

The terms error and exception are used often in the programming world. But more often than not, they are used interchangeably. Although subjective, I consider errors to be thrown by the JavaScript engine while exceptions are thrown by developers. …


Privacy issues of PWAs you might want to know more about

Image for post
Image for post
Photo by Bernard Hermant on Unsplash

Progressive Web Apps (PWAs)

Similar to the apple that fell on Newton’s head and changed the way we understood gravitational forces, progressive web apps are changing the way we understand applications by providing an app-like experience in the web form.

Progressive web apps are one of the technologies originally proposed by Google. The term progressive web app was first uttered by Frances Berriman and Alex Russell in 2015.

It was a way of describing applications that take advantage of new features supported by modern browsers, including service workers and web app manifests, and also lets users upgrade web apps to progressive web applications regardless of their native operating system. …


The most common data structures that you’ll get the most out of

Image for post
Image for post
Photo by Alex Ronsdorf on Unsplash

It is quite amazing how you can go from zero to a fully professional software engineer solely with the help of free resources available on the internet. But it can also be noted that developers who take this path often disregard the concept of data structures. They believe that knowledge of these data structures wouldn’t benefit them as they’ll only be developing simple applications.

But on the contrary, I believe learning data structures, right from the start, is essential. Data structures are mainly beneficial for building efficient applications. An application built using data structures will be more efficient than an application built without them. But this does not mean that you should use data structures for each and every requirement. …


Get an in-depth understanding of these two awesome methods

Image for post
Image for post
Photo by Ave Calvar on Unsplash

JavaScript has been steadily improving since its release in 1996. With many improvements coming in the form of ECMAScript versions, the most recent release being ES2020. You can read more about this release over here. I believe one of the prominent updates of JavaScript to be Promises, released in 2015 under the name ES6.

What is a Promise?

The MDN Docs defines a Promise as an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value. This might sound a bit too complicated for newbies.

Jecelyn explains Promises as follows: “Imagine you are a kid. …


Understanding all varieties of decorator functions

Image for post
Image for post
Photo by Manja Vitolic on Unsplash

What is a Decorator?

A decorator is simply a way of wrapping a function with another function to extend its existing capabilities. You “decorate” your existing code by wrapping it with another piece of code. This concept will not be new to those who are familiar with functional composition or higher-order functions.

Decorators aren’t something new. They have been present in other languages such as Python and even in JavaScript under functional programming. We will speak about this later on.

Why Use a Decorator?

Decorators allow you to write cleaner code and achieve composition. It also helps you extend the same functionality to several functions and classes. …

About

Mahdhi Rezvi

JavaScript Geek 😎 — Tech Writer with 1M+ views 👻 — Undergrad at UoM 🇱🇰 ❤️ — https://thisismahdhi.ml

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store