I am new to coding and javascript has some strange syntax at times. I know many methods of calling a function but this one intrigues me. I went through a code written by a developer and I deduced what was happening but couldn't understand how.
A function is called by placing ("") next to the function definition within ().
(function functionName() {console.log("Hello")}) ("")
// Hello
(functionName)("")
// evaluates the function
I tried searching but couldn't find it here. I would be grateful if someone can explain what is going on here (the concept). Let me know if this question is duplicated. Thanks.
(functionName)just evaluates to the function, and("")calls the function. In JavaScript, functions can be values, and can be used in expressions.+“next to” some numeric expressions, as in(2 * 3) + (4 - 5) === 5. Negation is!“next to” a boolean expression, as in!(1 > 2) === true. A function call is(…)“next to” a function expression, as in(Math.max)(10, 100) === 100.""kinda confused me.