1
function find() {
    console.log("Request handler 'find' was called.");
}
function display() {
    console.log("Request handler 'display' was called.");
}

exports.find = find; exports.display = display;

  1. sometime we call function with parentheses and sometimes we don't use them.

Like in DOM i get why we do no t use it with event Listeners because we want to them to only work when click occurs, But in node like the above example why we didn't used any parentheses?

Guerric P
  • 30,447
  • 6
  • 48
  • 86
Uzumaki
  • 27
  • 4
  • 7
    When you don't use parenthesis, you **don't call** the function. – Bergi Aug 04 '23 at 15:57
  • Functions are *first class citizens* in JavaScript. This means you can assign them to variables, pass them as arguments, and return them from other functions. – Devon Bessemer Aug 04 '23 at 16:01
  • 1
    No difference between nodejs exports and dom event handlers really: you don't call the function so that someone else can call the function at a time/place when it's desirable for them – Bergi Aug 04 '23 at 16:01

1 Answers1

4

without the parentheses you are assigning the function itself ( functions are first class objects ) whereas with the parentheses you are executing the function and assigning the resultant value

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104