What is the output of following code?
const a = 10 const b = a (() => console.log(b))()
The output is:
TypeError: a is not a function
If you thought the output as
10, then it is wrong. It would have been 10, if we explicitly placed semicolon at the end of each line.
const a = 10; const b = a; (() => console.log(b))(); // 10
Here the code in line 1 is
const a = 10
const a = 10const
const b = a(() => console.log(b))()
Above statement looks valid for JS engine. It tries to execute
a as a function. That is why, it results in TypeError.