Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
javascript
nodejs
promises
01callback.js
01callback.js
/** * basic usage of callbacks */ /* MAIN FUNCTION */ function addnum(x, cb) { console.log('x=' + x); cb(x); } /* CALLBACKS */ //callback which adds 5 function cb5(a) { var rez = a + 5; console.log('a+5=' + rez); } //callback which adds 100 function cb100(a) { var rez = a + 100; console.log('a+100=' + rez); } //execute main function with callback cb5 addnum(2, cb5); console.log(); //execute main function with callback cb100 addnum(2, cb100); /* $node 01callback x=2 a+5=7 x=2 a+100=102 */
Reload page
Preview
W3C validation
Edit Code
JS Console