Concatenation with Virgula and plus sign

0

I'm studying nodejs, and doing some testing with some native modules of the node I came across the following statement.

To print free memory on your computer:

const os = require('os');

console.log('Memoria Livre: ', os.freemem());

This comma separating the string from the constant is concatenation, correct?

If yes, what is the difference between using comma and / or +

console.log('Memoria Livre: ', os.freemem());

and / or

console.log('Memoria Livre: ' + os.freemem());

Are there any other means of concatenation in js?

    
asked by anonymous 21.08.2018 / 18:25

1 answer

3

This is not concatenation, the log(...) function is multi-argument.

When you do console.log('Memoria Livre: ' + os.freemem()); you are calling the function with 1 argument, which is a string 'Memoria Livre: ' + os.freemem() already in console.log('Memoria Livre: ', os.freemem()); you are passing 2 arguments to the function log(...) .

This is not a node.

  

console.log (obj1 [ obj2, ..., objN]);

     

console.log (msg [ subst1, ..., substN]);

console.log('a', 'b', 'c');
console.log('a'+'b'+'c');

let teste = {
  a: 'a',
  b: 'b'
}

console.log('a'+teste);

console.log('a', teste);
    
21.08.2018 / 18:34