I was working on a project and I was having trouble with the item deleting from local storage and it needed to map to a dumb value and so I used a custom data attribute and set up a new date object as the unique ID. The functionality wasn’t working and I have a feeling it was due to using the date object and it may be because there’s this eastern daylight time thing When you console.log it.
It wouldn’t always show the eastern daylight time thing when it was logged to the console but it wasn’t working so I created a new field called unique ID and set it to math.Round(math.Random()*100000)
This ultimately did the trick but I also had issues with the fact that I was using The strict quality operator and they were Not matching up in an if check because one was a string of one was a number. This is definitely not the first time the type of was the culprit of my issue.
So That’s lesson number one here: Make sure the type of your value is as expected.
The other lesson is just the importance of console.logging to ensure you’re getting what you expect at certain parts of your code. This seems straightforward enough but I literally will walk down line by line Make sure certain functions are firing and making sure that certain values and their type of is as expected.
Another thing I ran into when adding a chunk of HTML to the Dom/UI And also handling local storage Is that you may need to be conscious of The order in which you’re doing those two separate task. What I mean by this is if you’re removing an item from the Dom and then you’re trying to look up a custom data attribute (data-whatEvs) and match it with something in local storage this will fail because you removed it from the DOM before you are attempting to remove it from local storage. By the time you try and remove it from local storage it will fail because it’s no longer there.