JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – does arguments is a default function parameter

JavaScript Quiz – does arguments is a default function parameter

function default parameter –

The javascript functions arguments are a function default parameter that can access anytime and it contains all the param value in an array.

arguments is an Array-like object accessible inside functions that contain the values of the arguments passed to that function.

For more information about function arguments click here.

JavaScript Question

In this javascript quiz code, let’s find out does arguments is a default function parameter that is accessible inside a javascript function.

First, declare a function with function keyword with name getLength.

function getLength(){ … }

And inside a function there is default arguments which is an array like object. It can access the value of arguments passed to that function. We are checking the length of it

return arguments.length;

In the next step, create another variable length using let keyword and assign the result return from function getLength.

let length = getLength();

Finally, checking the value of length variable using console log.

console.log(length);

Any idea, what should be the output of above statement.

Answer – 0

Click To Run Code

Explanation

Now, you know the answer is 0. But why because it is just an array-like object not array. And even it’s not passed to function. Let me explain

So first, arguments are always accessible in function which contains all parameters.

arguments is an array-like object which has some properties like length, callee and arguments[@@iterator]

As no parameter is passed to function which you can clearly see and arguments hold the function parameter as an element.

At last, That’s why we get an answer “0“.

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JavaScript Quiz – can delete operator delete a global variable
  2. JavaScript Quiz – add new key in object after freeze is possible
  3. JS Quiz – new replaceAll method really replace all matching string
  4. JS Quiz – can it uppercase the string first letter

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link