In this tutorial that I recently published I talk about the issues you can run into and provide some examples. The examples shows how the mutable nature of objects can cause some unexpected consequences.
I then followed up this tutorial with a second tutorial that shows a possible solution. The solution is cloning objects. This is a technique commonly used in functional programming and is great to be aware of. I think the two tutorials together can be a great help.
This technique uses closure, but it uses it in a way that my not be intuitive, even to those that understand closure well. The basic idea is that your invoke a function that returns a function, and that returned function has access to (remembers) any data that was passed to it or establish at the time the function was returned.
This can be a powerful feature. Take a few moments and watch the tutorial and then tell me what you think.
At times you may come across the need to store some data in the browser so that when the user returns, you already have that data available. This can help solve a problem that might require the connecting and passing data to a server. But I have also found situations where even though I am passing data to a server it is helpful to store some data in the browser to ease the experience for the user.
I’ve recently published two tutorials on ways to store data in the browser. One uses localStorage and the other uses indexedDB.
LocalStorage is a pretty simple solution, but it does have some limitations such as the data can only be a string and there is a limit to how much data you can store. IndexedDB overcomes those limitations, but it is not quite as simple to use as localStorage.
Watch these two tutorial to dive deep into storing data in a browser.
Here is the problem with sort. Lets say I have an array of strings like this:
let things = [‘Building’, ‘Car’, ‘house’, ‘tree’, ‘bicycle’, ‘automobile’];
It will not sort correctly if I use:
The reason is that I have a mixture of upper and lowercase characters. The uppercase characters will sort first and we end up with this.
The solution is pretty simple; we just need to sort with the correct case. However, executing on that solution is not quite as simple. There are a number of different ways to do this. In the tutorial I chose to take advantage of a little known feature of sort; you can pass in a function to the sort method that can be used to determine the sort order. That makes sort a higher order function, and that was the reason I was using it as an example in the tutorial.
The end result is kind of cool.
If you would like to understand higher order function better or you are interested in the sort solution, take a look at this tutorial.
Now most of my life I have been slash deficient. When someone says forward slash or back slash, I don’t know which character it is. Some have tried to explain it by telling me to imagine a person leaning backwards or forwards. But that doesn’t help me at all because I don’t know which side has the face.
I think the biggest trick with these charaters is knowing the code to enter to get a certain character. Here are a couple of websites that have unicode and hexadecimal codes for characters:
OK, I admit it. I went through a phase when I first heard the word memoization where I ignored that it existed. After all, what could a technique with a name like that have to offer me?
Well, I finally threw away my pride, admitted it might be valuable and spent some time learning about it. Yes, it is a technique used in functional programming, but it is a technique that can be applied to any coding paradigm. And it can be quite valuable.
So to make my penance complete, I thought it appropriate to do a tutorial on memoization.
Now don’t let the term scare you off. It really is not a complex concept. The patterns for implementing it are a bit involved, but the concept itself is pretty easy to understand.
I just published the tutorial on memoization and you can access it below. Take a look and give me your thoughts.
So this begs the question, how to get started? Well, as mentioned there are several books published about the subject, and I will be reviewing some of those in the future. But I think a great first step is to really understand some of the methods of the Array object. These methods were designed around functional programming concepts. For example, map, forEach, every and reduce are a few that are valuable to understand. And it just so happens we have a tutorial on some of those methods.
I just completed two tutorials on exception handling. The first shows how to use try catch statements in your code. The second talks about when you should and should not use try catch.
Take a look at both videos and if you have any additional rules to add for using try catch statements post them here.
I love the word obfuscation. It seems to reflect its own definition. To obfuscate something is to make it difficult to understand.