Posts

Showing posts from December, 2022

How JavaScript uses hashing

Image
What does hashing mean? Hashing is a process that involves taking a piece of data, such as a string or number, and turning it into a fixed-size output called a hash . This hash is often used as a unique identifier for the original data and can be used for a variety of purposes, such as verifying the authenticity of a message or storing data in a database. Hashing One common use for hashing in JavaScript is in the creation of hash tables. A hash table is a data structure that uses hashes to store and retrieve data efficiently. The benefits of using a hash table are that it allows for fast insertion and retrieval of data, as well as efficient searching and sorting. One way that JavaScript uses hashing is through the use of objects. Objects in JavaScript are essentially hash tables, with keys being used as the hash and values being stored in the corresponding location in the table. This allows for fast access to data stored in an object, as the hash can be used to quickly locate the de...

Interfaces in object oriented programming languages and prototype-based languages

Image
What is an interface? In object oriented programming (OOP), an interface is a set of related methods that a class can implement . An interface defines the behaviour that a class must implement, but does not provide any implementation details. This allows for flexibility in how the class implements the behaviour, as long as it satisfies the requirements of the interface. One of the benefits of using OOP is that it allows for the creation of reusable code through inheritance and polymorphism . Inheritance allows a class to inherit the attributes and methods of a parent class , while polymorphism allows a class to have multiple implementations of a method depending on the context . Interfaces provide a way to specify the behaviour that a class must implement, without dictating how the behaviour is implemented. This allows for greater flexibility in the design of an OOP system. Interfaces Interfaces in JavaScript In contrast to OOP languages, prototype-based languages like JavaScript do ...

Big O notation basics for web developers

Image
What is "Big O"? Big O notation is a mathematical notation used to describe the performance of an algorithm. It measures the time and space complexity of an algorithm, which is the amount of time and memory it takes to run a specific task. That's maths. Why do I need to know about it? As web developers, it's important to understand Big O notation because it helps us evaluate the efficiency of our code . This allows us to identify potential bottlenecks and optimise our algorithms for better performance. For example, if we have a sorting algorithm that takes an input of n items, we can use Big O notation to determine the time and space complexity of the algorithm. If the algorithm has a time complexity of O( n 2 ), it means that it will take n 2  operations to sort the input. On the other hand, if the algorithm has a time complexity of O(n log n), it will take n log n operations to sort the input. In addition to helping us optimise our code, understanding Big O notation...

Concurrency in Web Development

Image
image source What is concurrency? This question comes up in many interviews so let's look at concurrency starting at the beginning. Concurrency refers to the ability of a computer program or system to run multiple tasks or processes simultaneously. This allows a program to run more efficiently by utilising the available resources of the computer, such as the processor, memory, and I/O devices, more effectively. Concurrency is an important concept in computer science and is often used to improve the performance of software applications. Concurrency and nodeJS In nodeJS, concurrency is achieved through the use of an event-driven, non-blocking I/O model . This means that the program does not have to wait for a task to complete before moving on to the next one. Instead, it can continue to process other tasks while waiting for the first task to complete. To implement concurrency in nodeJS, a program uses a single-threaded event loop to manage the concurrent execution of multiple tasks...