Skip to Content
Learning Node.js Development
book

Learning Node.js Development

by Andrew Mead
January 2018
Beginner
658 pages
13h 10m
English
Packt Publishing
Content preview from Learning Node.js Development

A complex synchronous program example

Let's go over a slightly more complex example, our second example. As shown in the following code, we start off by defining an add function. The add function takes arguments a and b, adds them together storing that in a variable called total, and returns total. Next, we add up 3 and 8, which is 11, storing it in the res variable. Then, we print out the response using the console.log statement, as shown here:

var add = (a, b) => { var total = a + b;  return total;};var res = add(3, 8);console.log(res);

That's it, nothing synchronous is happening. Once again we just need the Call Stack. The first thing that happens is we execute the main function; this starts the program we have here:

Then we run the first ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Node.js Development

Advanced Node.js Development

Andrew Mead
Node.js: Tools & Skills, 2nd Edition

Node.js: Tools & Skills, 2nd Edition

James Hibbard, Michael Wanyoike, Nilson Jacques, Jay Raj, Manjunath M
Your First Week With Node.js, 2nd Edition

Your First Week With Node.js, 2nd Edition

James Hibbard, Craig Buckler, Mark Brown, Nilson Jacques, James Kolce, Paul Orac, M. David Green, Florian Rappl

Publisher Resources

ISBN: 9781788395540Supplemental Content