Reputation: 179
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?
Upvotes: 0
Views: 55
Reputation: 324
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:
var
per scope (function) or one var
for each variable, promotes readability and keeps your declaration list free of clutter.var
per variable you can take more control of your versions and makes it easier to reorder the lines.var
per scope makes it easier to detect undeclared variables that may become implied globals.However you decide, the main principle should be, not to mix both styles!
Upvotes: 1