0

When requiring modules in node.js what is the difference when requiring in these two different ways:

var http = require('http');
var express = require('express');

and

var http = require('http'),
    express = require('express');

Is there a difference in compilation time? Or something else under the hood? Is the second example at all optimized?

Also, any pointers on where to go to find more information about what is going on under the hood for node.js/javascript code optimization?

Bill Headrick
  • 189
  • 1
  • 13
  • 1
    IMHO (if you used a tab) then the 2nd version is 3 characters shorter, and that's about it. I don't think there's any other difference performance wise – Gavriel Jan 12 '16 at 14:52

1 Answers1

1

As mentioned by @rmjoja this problem affects JavaScript code in general and not only node. I prefer to use var for every variable separately.

Here some reasons to use var per variable:

  • Using only one var per scope (function) or one var for each variable, promotes readability and keeps your declaration list free of clutter.
  • Using one var per variable you can take more control of your versions and makes it easier to reorder the lines.
  • One var per scope makes it easier to detect undeclared variables that may become implied globals.

source

However you decide, the main principle should be, not to mix both styles!

interested
  • 304
  • 1
  • 9