DEV Community

Cover image for ES6 with Javascript Concepts for React JS

ES6 with Javascript Concepts for React JS

Shubham Tiwari on December 17, 2022

Hello Everyone today i will discuss few concepts which you should know before moving onto React JS. Let's get started... ES6 Arrow Funct...
Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited
function regularFunction(num){
  return num
}

const arrowFunction = (num) => num
Enter fullscreen mode Exit fullscreen mode

These two things are not the same, in some cases the differences may not matter, but:

  • arrow functions have the this of the enclosing scope in which they are defined meaning they can't be used in prototypes or classes.
  • arrow functions are not hoisted meaning they must exist in the source code before their use, this can cause weird ordering issues for self referencing pairs of functions and means the purpose of your code will come after all of the utility functions it uses.

Arrow functions are incredibly useful, but they are also not actually shorter to declare if they are multiline and you are declaring the function as a variable to be called. However, you could define a map or a filter function with the whole function style shenanigans, if fact you used to have to, now that's nasty and arrow functions really shine in this area.

Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Actually I wrote they are doing the same thing , not they are same thing, what i meant is they are returning the number in the parameters
That's why i attached a link for the complete reference of the topic

Collapse
 
jonrandy profile image
Jon Randy 🎖️

A lot of stuff here is not related to ES6 at all

Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

Which one's?

Collapse
 
brense profile image
Rense Bakker

map, filter, reduce is ES5. Ternary operator has been there from the start.

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

Yeah but we can use these with ES6 features for more shorted code

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Well, if we want shorter code using ES6 features, we could rewrite your debounce:

const debounce = (fn, delay) => {
  let timer
  return () => {
    clearTimeout(timer)
    timer = setTimeout(fn, delay)
  }
}
Enter fullscreen mode Exit fullscreen mode

I'm not entirely sure why you wrapped fn in another function in the original?

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

Yeah The title should be ES6 combined with Javascript

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Higher order functions are just a programming concept made possible in languages where functions are treated as values, as JS does and always has.

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

But we can combine higher order function with ES6 features to make it more shorter that's i put it there

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

I think I should say ES6 with javascript combine

Collapse
 
codingjlu profile image
codingjlu

You might want to clarify on the React part. I think you should add relevant React snippets if you want to name your posts as so.