DEV Community

Cover image for JS Test #6: Variable number of arguments
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Updated on • Originally published at learn.coderslang.com

JS Test #6: Variable number of arguments

code-snippet
true or false? That is the question...

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

In JS, all functions have access to the internal arguments array that holds all arguments that were passed into the function.

We can access the elements of this array by index, thus expecting that both regularFunction and arrowFunction will return true.

The only issue is that arrow functions don’t have access to the arguments array.

There might be two separate outcomes in line 8. Most likely you’ll see the message ReferenceError: arguments is not defined. However, there also might be a different scenario. For example, if you run this code in Node.js, arguments[2] is likely to be evaluated to something like

Module {
  id: '.',
  path: '/workdir_path',
  exports: {},
  parent: null,
  filename: '/workdir_path/scriptName.js',
  loaded: false,
  children: [],
  paths: [
    '/node_modules'
  ]
}
Enter fullscreen mode Exit fullscreen mode

In which case, we’ll see false logged to the screen as 3 is not equal to the object described above.


ANSWER: false or ReferenceError will appear in the console depending on the execution environment

Top comments (0)