It's time to start the topic related to one more special key word that JavaScript engine gives us when we invoke the function.

arguments

It is next to a special variable: this, another element generated by the JavaScript engine.

This variable stores information about all values that we pass during the invocation of the function.

The elements passed to the function are called arguments, and JavaScript additionally gives us the special keyword that stores them all.

As you can see using arguments we can get data about how many arguments were passed and what were their values.

In JavaScript, the number of arguments passed to the function depends on us. In addition, in contrast to many programming languages, when we are invoking the function we are able to give any number we want.

Example:

As I mentioned above, we do not have to pass all the arguments. Although in the above interpretation, in the 7th line, only one argument was given, in JavaScript we will not be experiencing errors.

In addition, we have the option of setting default values for each of them. We will slightly modify the code.

Now, when we invoke the function, and don't pass the value of the job argument, by default we will get a string unemployed

Someone may ask, and why JavaScript does not return an error, but undefined?

Here, the hoisting is doing a job.

The JavaScript engine reserves space in memory for all arguments as it was with variables and functions.

Finally, I would like to mention one more thing,the spread.

This is a feature that appears from ES6 JavaScript, which allows us to do something like this:

As you can see, we added another argument named otherArguments and preceded it with three dots.

By doing this, we can pass any number of arguments that will be kept in the array.

Since I intend to spend more time on the ES6 features like spread in future posts, we will stop here and continue later on.

Next Post

I will want to present the Immediately Invoked Functions Expressions (IIFEs) that are loved by all.