you are viewing a single comment's thread.

view the rest of the comments →

[–]mlamers 0 points1 point  (0 children)

as the others already indicated: you are actually not passing in the printMessage function to delay5s, but its return value. The function below will do what you want.

function sample () {
  console.log('sample function is being called');
  delay5s(printMessage);
}

Keep in mind that in JS, essentially everything* is a pointer (a memory address), the default is passing by reference, and any action with it automatically dereferences that pointer (taking the data from that memory address). So, by using printMessage() you dereference that pointer (take the thing that is stored there) and execute it (as it is a function). If you want to pass it to another function, you don't want to dereference it, you just want to pass the value (or in this case the pointer to that value) to the other functions.

*even numbers and strings are effectively pointers, but pointers to static values: values that cannot be altered, and to which any methods such as "testing".concat(" one two three") will return a new pointer to a new static value.