-2

Well while studying how JavaScript behind the scenes work I read that arrow functions does not have their own 'this' keyword nor their own parameters.

//MAIN PROBLEM However, you can access the arguments without any problem. (when I saw the 'this' behavior then I assumed it's gonna be the same for the arguments and so the arguments value must be the value of the arguments of the parent function.)

Please someone explain how this is possible ???? that arrow functions could still access it's arguments even though "Arrow functions don't have their own arguments".

I checked it in code and it was true for the 'this' keyword when used inside the arrow function the value of 'this' is going to be the 'this' from it's parent function.

olabie
  • 24
  • 6
  • 2
    _"nor their own parameters"_ - arrow functions can **absolutely** have parameters, `(just, like, this) => ...`. Where did you read otherwise? They don't get [the `arguments` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments), maybe that's what you mean. – jonrsharpe Mar 09 '23 at 10:34
  • Yeah then does this mean that the argument's value is not stored in the arguments object ? @jonrsharpe – olabie Mar 09 '23 at 10:38

1 Answers1

-1

Arrow functions don't have their own arguments Allusion to arguments which is a legal and weird inheritance of JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments

function helpNor() {
  console.log("arguments normal function: ", arguments)
}

const helpArr = () => {
  if (typeof arguments !== "undefined")
    console.log("arguments arrow function: ", arguments)
  else
    console.log("arguments arrow function not exists")
}

helpNor("ls", "-a")
helpArr("ls", "-a")

However this does not mean that the arrow function does not have arguments

More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

const help = (...args) => {
  console.log("arguments: ", args)
}

help("ls", "-a")
Tachibana Shin
  • 2,605
  • 1
  • 5
  • 9
  • But how come arrow functions can still access their own arguments , although they don't have their own argument's object ? – olabie Mar 09 '23 at 10:49
  • refer to the links i provided `spread dot` is provided with the same version as `arrow function`refer to the links i provided `spread dot` is provided with the same version as `arrow function` – Tachibana Shin Mar 09 '23 at 10:50