So, let me tell you how to write code node like it's 2022. Look at this example, for example. So, we had to use multiple methods to iterate over an object. So, in this get total score, we had to use object keys and a for each to access the property inside of the object, and then assign the value to the totals. But now, we can do a for in, and we can access the key of the object And we can do it very easily, and with only one method. So, it's way easier to read, it's easy to return about. I know what I'm reading as soon as I put my eyes on it, way better.
Well, we had to concat strings to get phrases with variables, and LongAVI started with multi lines. These were very, very hard to create. In this example, I just created one that puts together three strings in this case. I had to use strings to spaces because I hated to add space in the end of this one, and here, I really need it because I can't add anything to this string directly. But now, I can use template literals and I can just make it work. I can do multi lines easily and everything I see is exactly what appears in a screen. So, much easier.
We had to use the hack to stringify and parse objects to clone them. And this wasn't a case for simple objects. You could do other stuff. And in load dash we had clone deep that made exactly the same thing as this code does. That is, basically get an object with complex and nested data and put it in another variable. As JavaScript would use a pointer to this one. If I only get like B equals A, I would get the value assigned as just a pointer to A and not actually a value of A. So I had to transform it in a string and then parse it to actually clone the value of the object. Well, that's a very complicated explanation to just copy an object. But now we can use structured clone. That is exactly what it says. It's a structured clone with all the properties, nested ones, and it just works as expected. I mean, it's very nice.
What about the default parameters? Oh, this one. Everyone that writes JavaScript in 2022 knows that the default parameters are very, very nice. Back in the day, you had to in the top of every function, you would have the variable equals variable or something, just like here.
Comments