Arrow Functions and variables

This is actually not an issue, but a question regarding the lesson.

ES6 provides us with the syntactic sugar to not have to write anonymous functions this way. Instead, you can use arrow function syntax:

const myFunc = () => {
  const myVar = "value";
  return myVar;

When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword return as well as the brackets surrounding the code. This helps simplify smaller functions into one-line statements:

const myFunc= () => "value"

So in the above arrow function, how is myVar variable declared? how do i know, or JS knows what type of variable is? it inherits the function declaration, ie const? var? let?

thank you.

1 Like

There is no variable named myVar in the second example. myFunc is just a function which returns a string. If we write the same function without using arrow function syntax, it would look like:

function myFunc() {
  return "value";

EDIT: Technically, to make the function a constant, it would look like:

const myFunc = function() {
  return "value";
1 Like

I understand. Thank you.

Answer to your EDIT:
Of course.
The original question just came because I got confused by the first example that doesn’t directly return the value, but is first assigned to a variable. So, i just wondered where did that assignation go? I understand now that they’re different examples.