Console Logging an Arrow Function

I am a bit confused with the console output , my understading is that if we write the function name in the console it will display only if there is a return exisit and in this casue it will either display [ ] or parsed value that is equal to z1 but rather it shows the whole arrow function.
am i missing something here, if someone can please clarify please.

let finalbuyitems = () => {
  let z1 = JSON.parse(window.localStorage.getItem("user-final") || "[]");
  return z1;
console.log(finalbuyitems); // console output below

function App() {
                 const [finalBuy, setfinalBuy] = useState(finalbuyitems());

console output below

What finalbuyitems is returning is a function itself, not the result of evaluating a function. This output looks correct to me.


1 Like

Thanks Kirupa, got it.
the point i was confusing was between console.log(finalbuyitems); and console.log(finalbuyitems());
if i am correct as the below statement.

In case of console.log(finalbuyitems); we are referring to the function so it will printout all the function
In case of console.log(finalbuyitems()); we are referring to the function-call so it will printout the return for the function call i.e z1

Yes, that is correct! :slight_smile:

1 Like