Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

42
Views
Are these 2 JavaScript statements equivalent?

These 2 statements seem to do the same thing.

const handleClick = () => alert('foo');

and

function handleClick() {
    alert('foo');
}

Are they identical and just syntactically different? The first one looks like a variable declaration, whereas the second one is clearly a function definition.

7 months ago · Juan Pablo Isaza
2 answers
Answer question

0

No, they are not the same thing. The arrow function has some limitations:

  • Does not have its own bindings to this or super, and should not be used as methods.
  • Does not have new.target keyword.
  • Not suitable for call, apply and bind methods, which generally rely on establishing a scope.
  • Can not be used as constructors.
  • Can not use yield, within its body.
7 months ago · Juan Pablo Isaza Report

0

ES6 arrow functions provide you with an alternative way to write a shorter syntax compared to the function expression. There is no performance difference.

Are arrow functions faster (more performant, lighter) than ordinary standalone function declaration in v8?

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.