Skip to content

Instantly share code, notes, and snippets.

@shelbyspees
Last active May 30, 2021 22:53
Show Gist options
  • Save shelbyspees/482d9cc3cf5ff36375894a615ab8796c to your computer and use it in GitHub Desktop.
Save shelbyspees/482d9cc3cf5ff36375894a615ab8796c to your computer and use it in GitHub Desktop.
this is how callbacks work, Shelby
function printName(name, callback) {
console.log(`Player name: ${name}`);
function callback(
// normally you'd define parameters here right?
// does this ever get used?
) {
// what's the point of these curly braces?
} (
console.log("inside callback")
);
}
printName("shelby");
// $ node printName.js
// inside printName.js!
// Player name: shelby
// inside callback
@shelbyspees
Copy link
Author

shelbyspees commented May 30, 2021

Things I tried

function myFunction (myParam, callback) {
  // do stuff
  callback(console.log("inside callback")); // did not work
}
function myFunction (myParam, callback) {
  // do stuff
  callback() = {
    console.log("inside callback"); // did not work
  }
}
function myFunction (myParam, callback) {
  // do stuff
  callback() => {
    console.log("inside callback"); // did not work
  }
}
function myFunction (myParam, callback) {
  // do stuff
  function callback() = {
    console.log("inside callback"); // did not work
  }
}
function myFunction (myParam, callback) {
  // do stuff
  function callback() {
    console.log("inside callback"); // did not work
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment