This is the config.json file:
{
"username": "myname",
"api-key": "test",
"name": "testname",
"version": 1
}
This is the node.js file
var fs=require("fs");
console.log("Start");
var contents=fs.readFileSync("config.json");
console.log("Contents: " +contents);
var config=JSON.parse(contents);
console.log("Username: ", config.username);
Now whether I use
console.log("Username: ", config.username);
or I use
console.log("Username:" +config.username);
I get the same result in the output. However it gives different results while logging other variables. Unable to get when "," is used and when "+" is used. Any pointers?
If you use + then that is a concatenation operator, and you pass a single string (or number) to log().
If you use a ,, then you are passing multiple arguments.
If you pass multiple arguments, and you aren't using a formatting string, then they will each get logged via inspect.
See the documentation for console.log and util.inspect for more details.
The difference is that the + operator varies from a concatenation operator if one or more of the variables is a string, versus an addition operator if both variables are non-stringified numbers. The , separator always converts each variable to a string separately and logs them separately.