DEV Community

loading...

Discussion on: PHP 8 features I wish also existed in JavaScript

Collapse
wearypossum4770 profile image
Stephen Smith

Also I think maybe our termi ology may be different. Parameters are declared with the function definition, what the function is expecting. Arguments are passed to the function when called. So when arguments are destructured in the parameters it doesn't use an object, they are just local scope variables.
developer.mozilla.org/en-US/docs/G...

function foo({
  a=0,  <- parameter
  b=0,  <- parameter
  c=0,  <- parameter
  d=0,  <- parameter
  e=0,  <- parameter
  f=0,   <- parameter
  ...rest
  }){
return d
}

foo({d:9,h:10})  <- arguments
Enter fullscreen mode Exit fullscreen mode

Destructure, assignment, rest, and spread are all JS language specific techniques to make code readable and cleaner. Different languages can feel clustered if you are not use to working with it, but that is why different languages exist because they all are useful for some use case. Like why can PHP use keywords "let, const, var" to declare variables? Or why can all languages do as Python and just have no keyword required for variable declaration?

.

Collapse
devmount profile image
Andreas Author

Thank you for this clarification 👏🏻 I do love the variety of programming languages, but sometimes you used a feature in one language you really liked and wished it also existed in another, that's all 😅