Why can't we use const variable without a function in this case?

Tell us what’s happening:
Hello,

I’m a bit confused why are we using inline functions in this case and what would be a use of it in regular practice.

Looks like (i) would work the same as (ii) in this case:

const myFunc = () => "value"; // (i)

const myFunc  = "value"; // (ii)

and same here:


const magic = () => new Date(); // (i)

const magic = new Date(); // (ii)

So I’m a bit confused in what cases we would need to write those inline functions when we could declare a constant variable and get the same result.

Thank you!

Best regards,
Konstantin

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36.

Challenge: Use Arrow Functions to Write Concise Anonymous Functions

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions

Mostly, this is just a quick exercise to introduce fat arrow functions.

This const myFunc = () => "value"; is known as arrow function, which would be the same as a regular function:

function myFunc() { 
  return "value"; 
}

It should not be confused with a variable.