Javascript course — Javascript the good parts frequently used in React
Part #6: Use the good parts avoid the bad parts
The problem when the function takes more parameters
The problem with function arguments is that it gets complicated if the function can take more then one required and one optional parameter.
Reference of maximum parameters you should use
printCool
function can have two parameters- the second parameter is optional
Reference of a function with more parameters then you should use
What if we want to call the function with the different end but keep the start
- if you want to change the
end
parameter you have to reenterstart
argument - can you understand what is happening what are those values
- imagine more arguments 🤯
printSolid("Javascript", "* >>> *", "* custom end *")
Destructuring function parameters
How to do destructuring objects was covered in Part #5. As you already know function can have an object as an input.
Object argument is commonly used in React components and you will see this practice often.
Iterating over List or Collection of Objects
Most courses will torture you with for loops and while loops. We will have a different approach. We will use Array.map
. The map is a method of Array object.
items.map((item) => { return item; }); // default does nothing
- map always return a new Array
🚧 warning array will shill use reference for the nested arrays and other objects.
Testing javascript
You can use https://jestjs.io/ it is most popular and requires zero configuration.
Unit testing is better than debugging, me
Read about testing