DEV Community

loading...
Cover image for JS Test #6: Variable number of arguments

JS Test #6: Variable number of arguments

Coderslang: Become a Software Engineer
Teaching you to code at js.coderslang.com - JavaScript, HTML, CSS, Node.js, React.js, React Native
Originally published at learn.coderslang.com Updated on ・1 min read

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

Discussion (0)