This takes the constant array “colors” and adds the string “light” before them. This code would have an output that looks like this:
You can imagine how these methods would come in handy during everyday programming. Imagine you are trying to write a program that adds the prefix of a person’s name, Mr., Mrs., etc. You could replace the hard coded string with a variable that relies on user input. Then, from that point on in the code, when the user is referenced, they will be remembered as Mr. or Mrs. User.
We can fix this error by simply wrapping our function body in curly braces like so:
And now the function will perform the correct math and will return 3.
To sum it up