DEV Community

Discussion on: Know the difference between theses JS concept in order to skill up #1

Collapse
eecolor profile image
EECOLOR

Hello, these are some interesting comparisons.

I was kinda surprised to see no example of spread in the 'Spread vs rest' section. A few examples of spread:

someFunction(...someArray)

...

const x = [...somethingIterable]

...

const y = { ...somethingIterable }
Enter fullscreen mode Exit fullscreen mode

I was also surprised to see no example of function in the 'Hoisting' section. It is the one form of hoisting that I find very useful because it allows you to optimize the readability of the code.

someFunction() // "hello"

function someFunction() {
  console.log('hello')
}

...

function SomeComponent() {
  return <button type='button' onClick={handleClick}>click</button>

  function handleClick(e) {
    ...
  }
}
Enter fullscreen mode Exit fullscreen mode

An example that hopefully communicates how you can improve readability by relying on hoisting:

function mySpecialAction() {
  const resultOfThis = doThis()
  const resultOfThat = doThat(resultOfThis)
  return resultOfThat
}

function doThis(someInput) {
  ...
}

function doThat(someInput) {
  ...
}
Enter fullscreen mode Exit fullscreen mode

This helps the reader by obtaining an overview before diving into details.

Collapse
codeoz profile image
CodeOz Author

Nice thank you!