Js difference in the function call, the function name in parentheses and without parentheses


function test(){
return 1;
}
var a=test;
console.log(a);//输出[Function: test]
var b=test();
console.log(b);//输出1


The function name is an object, and the object is stored in memory, the function name is a pointer to the object pointer.

var a = test object is a pointer to the function a.

var b = test () followed by parentheses means the call immediately, the return value of the function range. You can also indicates that the call immediately after the function body enclosed in parentheses.
----------------
Disclaimer: This article is CSDN bloggers "to accommodate i 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source and this link statement.
Original link: https: //blog.csdn.net/qq_36619427/article/details/80528697

Guess you like

Origin www.cnblogs.com/Alon-Td/p/12025390.html